|
| 1 | +const CHECK_INTERVAL = 500 |
| 2 | +const NEXT_DELAY = 500 |
| 3 | +const MAX_ATTEMPTS = 60 |
| 4 | + |
| 5 | +function hasSaveButton(): boolean { |
| 6 | + return [...document.querySelectorAll('[id^="modal-dialog"] button')].some((b) => |
| 7 | + (b as HTMLButtonElement).innerText.toLowerCase().includes('save'), |
| 8 | + ) |
| 9 | +} |
| 10 | + |
| 11 | +function findNextButton(): HTMLButtonElement | undefined { |
| 12 | + return [...document.querySelectorAll<HTMLButtonElement>('[id^="modal-dialog"] button')].find( |
| 13 | + (b) => b.innerText.trim().toLowerCase() === 'next', |
| 14 | + ) |
| 15 | +} |
| 16 | + |
| 17 | +function autoClickNoUntilSave() { |
| 18 | + console.log('[AutoAge] Started: auto-selecting false/NONE until Save') |
| 19 | + |
| 20 | + let attempt = 0 |
| 21 | + let seenSave = false |
| 22 | + let warnedNoFalse = false |
| 23 | + |
| 24 | + function processStep() { |
| 25 | + attempt++ |
| 26 | + |
| 27 | + if (hasSaveButton()) { |
| 28 | + console.log('[AutoAge] Save button detected, stopping') |
| 29 | + seenSave = true |
| 30 | + return |
| 31 | + } |
| 32 | + |
| 33 | + if (attempt >= MAX_ATTEMPTS) { |
| 34 | + console.warn('[AutoAge] Max attempts reached, stopping') |
| 35 | + return |
| 36 | + } |
| 37 | + |
| 38 | + const targets = document.querySelectorAll( |
| 39 | + '[id^="modal-dialog"] input[type="radio"][value="false"]:not(:checked), ' + |
| 40 | + '[id^="modal-dialog"] input[type="radio"][value="NONE"]:not(:checked), ' + |
| 41 | + '[id^="modal-dialog"] input[type="radio"][value="NO"]:not(:checked)', |
| 42 | + ) |
| 43 | + |
| 44 | + if (targets.length > 0) { |
| 45 | + console.log(`[AutoAge] Found ${targets.length} false/NONE/NO options, clicking...`) |
| 46 | + targets.forEach((el) => (el as HTMLElement).click()) |
| 47 | + warnedNoFalse = false |
| 48 | + // Wait for user to see the selections before clicking Next |
| 49 | + setTimeout(() => { |
| 50 | + clickNextAndContinue(targets.length) |
| 51 | + }, NEXT_DELAY) |
| 52 | + return |
| 53 | + } else { |
| 54 | + if (!warnedNoFalse) { |
| 55 | + console.log('[AutoAge] No false/NONE/NO options found in this step (may be the last step or already selected)') |
| 56 | + warnedNoFalse = true |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + clickNextAndContinue(targets.length) |
| 61 | + } |
| 62 | + |
| 63 | + function clickNextAndContinue(targetCount: number) { |
| 64 | + if (!seenSave) { |
| 65 | + const nextBtn = findNextButton() |
| 66 | + if (nextBtn) { |
| 67 | + console.log('[AutoAge] Found Next button, clicking...') |
| 68 | + nextBtn.click() |
| 69 | + } else if (targetCount === 0) { |
| 70 | + console.log('[AutoAge] No Next button found and no false/NONE to click, checking if Save step is reached') |
| 71 | + } |
| 72 | + } |
| 73 | + setTimeout(processStep, CHECK_INTERVAL) |
| 74 | + } |
| 75 | + |
| 76 | + setTimeout(processStep, 1200) |
| 77 | +} |
| 78 | + |
| 79 | +GM_registerMenuCommand('Auto-select NO/NONE (Age Ratings)', autoClickNoUntilSave, 'n') |
| 80 | +console.log('[AutoAge] Script loaded. Use menu "Auto-select NO/NONE (Age Ratings)" to start') |
0 commit comments