Update Auto-Image.js

This commit is contained in:
jamz-uk authored and GitHub committed 2025-08-13 19:27:50 +01:00
1 parent ca7ad768f1
commit 17f8d0ae95
1 file changed
+22 -16
+22 -16
View File
@@ -1525,25 +1525,30 @@ async function autoRefreshSequence() {
if (success === "token_error") { if (success === "token_error") {
if (state.autoRefresh) { if (state.autoRefresh) {
// CAPTCHA expired: wait until enough charges, then refresh // CAPTCHA expired: keep trying refresh and retry until token works
updateUI("captchaNeeded", "error"); updateUI("captchaNeeded", "error");
Utils.showAlert(Utils.t("captchaNeeded"), "error"); Utils.showAlert(Utils.t("captchaNeeded"), "error");
while (state.currentCharges <= 1) { let retry;
updateUI( do {
state.language === 'pt' // wait until enough charges available
? `⌛ Sem cargas. Esperando ${Math.ceil(state.cooldown/1000)}s...` while (state.currentCharges <= 1) {
: `⌛ No charges. Waiting ${Math.ceil(state.cooldown/1000)}s...`, updateUI(
'status' state.language === 'pt'
); ? `⌛ Sem cargas. Esperando ${Math.ceil(state.cooldown/1000)}s...`
await Utils.sleep(state.cooldown); : `⌛ No charges. Waiting ${Math.ceil(state.cooldown/1000)}s...`,
const info = await WPlaceService.getCharges(); 'status'
state.currentCharges = Math.floor(info.charges); );
state.cooldown = info.cooldown; await Utils.sleep(state.cooldown);
} const info = await WPlaceService.getCharges();
await autoRefreshSequence(); state.currentCharges = Math.floor(info.charges);
// retry this batch state.cooldown = info.cooldown;
const retry = await sendPixelBatch(pixelBatch, regionX, regionY); }
await autoRefreshSequence();
// retry this batch after refresh
retry = await sendPixelBatch(pixelBatch, regionX, regionY);
} while (retry === "token_error");
if (retry === true) { if (retry === true) {
// successful retry: mark pixels and continue
pixelBatch.forEach(p => { pixelBatch.forEach(p => {
state.paintedMap[p.localY][p.localX] = true; state.paintedMap[p.localY][p.localX] = true;
state.paintedPixels++; state.paintedPixels++;
@@ -1554,6 +1559,7 @@ async function autoRefreshSequence() {
pixelBatch = []; pixelBatch = [];
continue; continue;
} }
// if retry is false (non-token error), fall through to fallback
} }
// fallback: halt on token error // fallback: halt on token error
state.stopFlag = true; state.stopFlag = true;