From 197a10205c44258405b51c14b834f4b1b3952cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=A9ng?= <99890979+maiminhdung@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:00:16 +0700 Subject: [PATCH] delete check after 30s --- Auto-Image.js | 146 ++++++++++++++++++++++---------------------------- 1 file changed, 65 insertions(+), 81 deletions(-) diff --git a/Auto-Image.js b/Auto-Image.js index adb1bd7..60106b9 100644 --- a/Auto-Image.js +++ b/Auto-Image.js @@ -1120,96 +1120,80 @@ state.paintedMap = Array(height).fill().map(() => Array(width).fill(false)); } - // Set up interval to refresh charges every 30 seconds while painting - let chargesInterval = setInterval(async () => { - // Only update if still running - if (state.running && !state.stopFlag) { - const chargeUpdate = await WPlaceService.getCharges(); - state.currentCharges = chargeUpdate.charges; - state.cooldown = chargeUpdate.cooldown; - updateStats(); - } - }, 30000); + outerLoop: + for (let y = startRow; y < height; y++) { + for (let x = (y === startRow ? startCol : 0); x < width; x++) { + // If stop is requested, save the last position and exit + if (state.stopFlag) { + state.lastPosition = { x, y }; + updateUI('paintingPaused', 'warning', { x, y }); + break outerLoop; + } - try { - outerLoop: - for (let y = startRow; y < height; y++) { - for (let x = (y === startRow ? startCol : 0); x < width; x++) { - // If stop is requested, save the last position and exit - if (state.stopFlag) { - state.lastPosition = { x, y }; - updateUI('paintingPaused', 'warning', { x, y }); + // Skip pixel if already painted (for resume) + if (state.paintedMap[y][x]) continue; + + const idx = (y * width + x) * 4; + const r = pixels[idx]; + const g = pixels[idx + 1]; + const b = pixels[idx + 2]; + const alpha = pixels[idx + 3]; + + // Skip transparent or white pixels + if (alpha < CONFIG.TRANSPARENCY_THRESHOLD) continue; + if (Utils.isWhitePixel(r, g, b)) continue; + + const rgb = [r, g, b]; + const colorId = findClosestColor(rgb, state.availableColors); + + if (state.currentCharges < 1) { + updateUI('noCharges', 'warning', { time: Utils.formatTime(state.cooldown) }); + await Utils.sleep(state.cooldown); + + const chargeUpdate = await WPlaceService.getCharges(); + state.currentCharges = chargeUpdate.charges; + state.cooldown = chargeUpdate.cooldown; + } + + const pixelX = startX + x; + const pixelY = startY + y; + + const success = await WPlaceService.paintPixelInRegion( + regionX, + regionY, + pixelX, + pixelY, + colorId + ); + + // If CAPTCHA/token error, stop and notify + if (success === 'token_error') { + state.stopFlag = true; + updateUI('captchaNeeded', 'error'); + Utils.showAlert(Utils.t('captchaNeeded'), 'error'); break outerLoop; - } + } - // Skip pixel if already painted (for resume) - if (state.paintedMap[y][x]) continue; + if (success) { + state.paintedPixels++; + state.currentCharges--; + state.paintedMap[y][x] = true; // Mark pixel as painted - const idx = (y * width + x) * 4; - const r = pixels[idx]; - const g = pixels[idx + 1]; - const b = pixels[idx + 2]; - const alpha = pixels[idx + 3]; - - // Skip transparent or white pixels - if (alpha < CONFIG.TRANSPARENCY_THRESHOLD) continue; - if (Utils.isWhitePixel(r, g, b)) continue; - - const rgb = [r, g, b]; - const colorId = findClosestColor(rgb, state.availableColors); - - if (state.currentCharges < 1) { - updateUI('noCharges', 'warning', { time: Utils.formatTime(state.cooldown) }); - await Utils.sleep(state.cooldown); - - const chargeUpdate = await WPlaceService.getCharges(); - state.currentCharges = chargeUpdate.charges; - state.cooldown = chargeUpdate.cooldown; - } - - const pixelX = startX + x; - const pixelY = startY + y; - - const success = await WPlaceService.paintPixelInRegion( - regionX, - regionY, - pixelX, - pixelY, - colorId + state.estimatedTime = Utils.calculateEstimatedTime( + state.totalPixels - state.paintedPixels, + state.currentCharges, + state.cooldown ); - // If CAPTCHA/token error, stop and notify - if (success === 'token_error') { - state.stopFlag = true; - updateUI('captchaNeeded', 'error'); - Utils.showAlert(Utils.t('captchaNeeded'), 'error'); - break outerLoop; - } - - if (success) { - state.paintedPixels++; - state.currentCharges--; - state.paintedMap[y][x] = true; // Mark pixel as painted - - state.estimatedTime = Utils.calculateEstimatedTime( - state.totalPixels - state.paintedPixels, - state.currentCharges, - state.cooldown - ); - - if (state.paintedPixels % CONFIG.LOG_INTERVAL === 0) { - updateStats(); - updateUI('paintingProgress', 'default', { - painted: state.paintedPixels, - total: state.totalPixels - }); - } + if (state.paintedPixels % CONFIG.LOG_INTERVAL === 0) { + updateStats(); + updateUI('paintingProgress', 'default', { + painted: state.paintedPixels, + total: state.totalPixels + }); } } } - } finally { - // Always clear the interval when painting stops or finishes - clearInterval(chargesInterval); } // If stopped, keep last position for resume; if finished, reset lastPosition and paintedMap