From 070ce343fd6e7a0c43b5870e04fbee925a5284ac Mon Sep 17 00:00:00 2001 From: jamz-uk <222520099+jamz-uk@users.noreply.github.com> Date: Wed, 13 Aug 2025 19:13:39 +0100 Subject: [PATCH] Update Auto-Image.js --- Auto-Image.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/Auto-Image.js b/Auto-Image.js index 45d1402..36a925a 100644 --- a/Auto-Image.js +++ b/Auto-Image.js @@ -128,10 +128,11 @@ startPosition: null, selectingPosition: false, region: null, - minimized: false, - lastPosition: { x: 0, y: 0 }, - estimatedTime: 0, - language: "en", + minimized: false, + lastPosition: { x: 0, y: 0 }, + estimatedTime: 0, + autoRefresh: true, + language: "en", }; // Global variable to store the captured CAPTCHA token. @@ -1413,10 +1414,60 @@ } }; - // Check for saved progress after a short delay to let UI settle setTimeout(checkSavedProgress, 1000); } +const sleep = Utils.sleep; +const waitForSelector = async (selector, interval = 200, timeout = 5000) => { + const start = Date.now(); + while (Date.now() - start < timeout) { + const el = document.querySelector(selector); + if (el) return el; + await sleep(interval); + } + return null; +}; + +async function autoRefreshSequence() { + const paintBtn = await waitForSelector( + 'button.btn.btn-primary.btn-lg, button.btn-primary.sm\\:btn-xl' + ); + paintBtn?.click(); + + await sleep(500); + + const transBtn = await waitForSelector('button#color-0'); + transBtn?.click(); + + await sleep(500); + + const canvas = await waitForSelector('canvas'); + if (canvas) { + canvas.setAttribute('tabindex','0'); + canvas.focus(); + const rect = canvas.getBoundingClientRect(); + const centerX = Math.round(rect.left + rect.width/2); + const centerY = Math.round(rect.top + rect.height/2); + const moveEvt = new MouseEvent('mousemove', { clientX: centerX, clientY: centerY, bubbles: true }); + canvas.dispatchEvent(moveEvt); + const down = new KeyboardEvent('keydown', { key: ' ', code: 'Space', bubbles: true }); + const up = new KeyboardEvent('keyup', { key: ' ', code: 'Space', bubbles: true }); + canvas.dispatchEvent(down); + canvas.dispatchEvent(up); + } + + await sleep(500); + + let confirmBtn = await waitForSelector( + 'button.btn.btn-primary.btn-lg, button.btn.btn-primary.sm\\:btn-xl' + ); + if (!confirmBtn) { + const all = Array.from(document.querySelectorAll('button.btn-primary')); + confirmBtn = all[all.length - 1] || null; + } + confirmBtn?.click(); +} + async function processImage() { const { width, height, pixels } = state.imageData; const { x: startX, y: startY } = state.startPosition; @@ -1473,6 +1524,28 @@ const success = await sendPixelBatch(pixelBatch, regionX, regionY); if (success === "token_error") { + if (state.autoRefresh) { + // CAPTCHA expired: auto-refresh and retry + updateUI("captchaNeeded", "error"); + Utils.showAlert(Utils.t("captchaNeeded"), "error"); + await autoRefreshSequence(); + // retry this batch + const retry = await sendPixelBatch(pixelBatch, regionX, regionY); + if (retry === true) { + pixelBatch.forEach(p => { + state.paintedMap[p.localY][p.localX] = true; + state.paintedPixels++; + }); + state.currentCharges -= pixelBatch.length; + updateStats(); + updateUI("paintingProgress", "default", { painted: state.paintedPixels, total: state.totalPixels }); + pixelBatch = []; + // continue painting + continue; + } + // if retry fails, stop + } + // manual or retry failure state.stopFlag = true; updateUI("captchaNeeded", "error"); Utils.showAlert(Utils.t("captchaNeeded"), "error"); @@ -1591,4 +1664,4 @@ } createUI(); -})(); \ No newline at end of file +})();