From 17f8d0ae951e136b0b01acfcd3aabae6904a60a3 Mon Sep 17 00:00:00 2001 From: jamz-uk <222520099+jamz-uk@users.noreply.github.com> Date: Wed, 13 Aug 2025 19:27:50 +0100 Subject: [PATCH] Update Auto-Image.js --- Auto-Image.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Auto-Image.js b/Auto-Image.js index dd5519a..2467416 100644 --- a/Auto-Image.js +++ b/Auto-Image.js @@ -1525,25 +1525,30 @@ async function autoRefreshSequence() { if (success === "token_error") { if (state.autoRefresh) { - // CAPTCHA expired: wait until enough charges, then refresh + // CAPTCHA expired: keep trying refresh and retry until token works updateUI("captchaNeeded", "error"); Utils.showAlert(Utils.t("captchaNeeded"), "error"); - while (state.currentCharges <= 1) { - updateUI( - state.language === 'pt' - ? `⌛ Sem cargas. Esperando ${Math.ceil(state.cooldown/1000)}s...` - : `⌛ No charges. Waiting ${Math.ceil(state.cooldown/1000)}s...`, - 'status' - ); - await Utils.sleep(state.cooldown); - const info = await WPlaceService.getCharges(); - state.currentCharges = Math.floor(info.charges); - state.cooldown = info.cooldown; - } - await autoRefreshSequence(); - // retry this batch - const retry = await sendPixelBatch(pixelBatch, regionX, regionY); + let retry; + do { + // wait until enough charges available + while (state.currentCharges <= 1) { + updateUI( + state.language === 'pt' + ? `⌛ Sem cargas. Esperando ${Math.ceil(state.cooldown/1000)}s...` + : `⌛ No charges. Waiting ${Math.ceil(state.cooldown/1000)}s...`, + 'status' + ); + await Utils.sleep(state.cooldown); + const info = await WPlaceService.getCharges(); + state.currentCharges = Math.floor(info.charges); + state.cooldown = info.cooldown; + } + await autoRefreshSequence(); + // retry this batch after refresh + retry = await sendPixelBatch(pixelBatch, regionX, regionY); + } while (retry === "token_error"); if (retry === true) { + // successful retry: mark pixels and continue pixelBatch.forEach(p => { state.paintedMap[p.localY][p.localX] = true; state.paintedPixels++; @@ -1554,6 +1559,7 @@ async function autoRefreshSequence() { pixelBatch = []; continue; } + // if retry is false (non-token error), fall through to fallback } // fallback: halt on token error state.stopFlag = true;