feat: Fully implemented Auto-Switch feature

This commit is contained in:
MiraclePatrickLumowa authored and GitHub committed 2025-09-20 00:22:09 +08:00
1 parent f7a0c7f495
commit 954eed9d98
20 files changed
+2051 -449

No files matched your search

File diff suppressed because it is too large. Load diff
+15 -10
View File
@@ -1773,16 +1773,21 @@
const targetColor = Utils.resolveColor([originalR, originalG, originalB], state.availableColors);
const currentColor = Utils.resolveColor(currentPixel.slice(0, 3), state.availableColors);
if (targetColor.id !== currentColor.id) {
damagedPixels.push({
x,
y,
originalColor: targetColor,
currentColor: currentColor,
originalRgb: [originalR, originalG, originalB],
currentRgb: currentPixel.slice(0, 3),
isDamagedTransparent: false
});
if (targetColor.id === currentColor.id) {
// Pixel is already correctly painted - skip it
continue;
}
// Pixel has wrong color - mark as damaged
damagedPixels.push({
x,
y,
originalColor: targetColor,
currentColor: currentColor,
originalRgb: [originalR, originalG, originalB],
currentRgb: currentPixel.slice(0, 3),
isDamagedTransparent: false
});
wrongColorPixelsDetected++;
if (!state.autonomousMode || wrongColorPixelsDetected <= 10) {
+1 -1
View File
@@ -10,7 +10,7 @@
/**
* ImageProcessor - Handles image loading, processing, color conversion, and dithering for WPlace AutoBot
* Extracted from Auto-Image.js for better modularity and reusability
* Extracted from Auto-Image.js for better modularity and reusabilit
*/
class ImageProcessor {
constructor(imageSrc = null) {
+1 -1
View File
@@ -10,7 +10,7 @@
/**
* OverlayManager - Handles overlay processing, tile chunking, and canvas operations for WPlace AutoBot
* Extracted from Auto-Image.js for better modularity and reusability
* Extracted from Auto-Image.js for better modularity and reusabilityc
*/
class OverlayManager {
constructor() {
+2 -2
View File
@@ -5,12 +5,12 @@
// @description Turnstile token management for WPlace AutoBot
// @author Wbot
// @match https://wplace.live/*
// @grant none
// @grant nones
// ==/UserScript==
/**
* TokenManager - Handles Turnstile token generation, caching, and validation for WPlace AutoBot
* Extracted from Auto-Image.js for better modularity and reusability
* Extracted from Auto-Image.js for better modularity and reusabilitys
*/
class TokenManager {
constructor() {
+38 -4
View File
@@ -1,6 +1,6 @@
/**
* WPlace AutoBOT - Utils Manager
* Centralized utility functions for the WPlace automation system
* Centralized utility functions for the WPlace automation systemds
*/
class WPlaceUtilsManager {
@@ -408,6 +408,16 @@ class WPlaceUtilsManager {
}
formatTime(ms) {
// Handle invalid or infinite values
if (!Number.isFinite(ms) || ms < 0) {
return '--:--:--';
}
// Handle very large values (more than 999 days)
if (ms > 999 * 24 * 60 * 60 * 1000) {
return '999d+';
}
const seconds = Math.floor((ms / 1000) % 60);
const minutes = Math.floor((ms / (1000 * 60)) % 60);
const hours = Math.floor((ms / (1000 * 60 * 60)) % 24);
@@ -423,15 +433,34 @@ class WPlaceUtilsManager {
}
calculateEstimatedTime(remainingPixels, charges, cooldown) {
if (remainingPixels <= 0) return 0;
// Safety checks for input parameters
if (!Number.isFinite(remainingPixels) || remainingPixels <= 0) return 0;
if (!Number.isFinite(charges) || charges <= 0) charges = 1;
if (!Number.isFinite(cooldown) || cooldown <= 0) cooldown = 30000; // Default 30s
const paintingSpeed = window.state?.paintingSpeed || 5;
if (!Number.isFinite(paintingSpeed) || paintingSpeed <= 0) {
// Fallback calculation without painting speed
const cyclesNeeded = Math.ceil(remainingPixels / Math.max(charges, 1));
const timeFromCharges = cyclesNeeded * cooldown;
return Math.min(timeFromCharges, 999 * 24 * 60 * 60 * 1000); // Cap at 999 days
}
const paintingSpeedDelay = window.state.paintingSpeed > 0 ? 1000 / window.state.paintingSpeed : 1000;
const paintingSpeedDelay = 1000 / paintingSpeed;
const timeFromSpeed = remainingPixels * paintingSpeedDelay;
const cyclesNeeded = Math.ceil(remainingPixels / Math.max(charges, 1));
const timeFromCharges = cyclesNeeded * cooldown;
return timeFromSpeed + timeFromCharges;
const totalTime = timeFromSpeed + timeFromCharges;
// Safety check to prevent infinity and cap at reasonable maximum
if (!Number.isFinite(totalTime) || totalTime < 0) {
return 0;
}
// Cap at 999 days to prevent display issues
return Math.min(totalTime, 999 * 24 * 60 * 60 * 1000);
}
// Painted pixel tracking helpers
@@ -472,6 +501,11 @@ class WPlaceUtilsManager {
return false;
}
// Alias for isPixelPainted - used in pre-filtering logic
isPixelMarkedPainted(x, y, regionX = 0, regionY = 0) {
return this.isPixelPainted(x, y, regionX, regionY);
}
// Smart save
shouldAutoSave() {
const now = Date.now();