Update Auto-Image.js

This commit is contained in:
jamz-uk authored and GitHub committed 2025-08-13 19:49:14 +01:00
1 parent 76cd7eb302
commit db8f607de8
1 file changed
+5 -78
+5 -78
View File
@@ -128,11 +128,10 @@
startPosition: null,
selectingPosition: false,
region: null,
minimized: false,
lastPosition: { x: 0, y: 0 },
estimatedTime: 0,
autoRefresh: true,
language: "en",
minimized: false,
lastPosition: { x: 0, y: 0 },
estimatedTime: 0,
language: "en",
};
// Global variable to store the captured CAPTCHA token.
@@ -1414,60 +1413,10 @@
}
};
// 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;
@@ -1524,28 +1473,6 @@ async function autoRefreshSequence() {
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");