diff --git a/Auto-Image.js b/Auto-Image.js index 29c878c..88e5158 100644 --- a/Auto-Image.js +++ b/Auto-Image.js @@ -604,9 +604,11 @@ enable() { this.isEnabled = true; } + disable() { this.isEnabled = false; } + clear() { this.disable(); this.imageBitmap = null; @@ -1030,10 +1032,8 @@ await Utils.sleep(100); } - console.warn( - `β Timeout waiting for tiles: ${requiredTiles.length} required, - ${requiredTiles.filter((k) => this.originalTiles.has(k)).length} loaded` - ); + console.warn(`β Timeout waiting for tiles: ${requiredTiles.length} required, + ${requiredTiles.filter((k) => this.originalTiles.has(k)).length} loaded`); return false; } } @@ -1116,26 +1116,56 @@ } async function handleCaptchaWithRetry() { - const startTime = Date.now(); - try { - const sitekey = Utils.detectSitekey(); - console.log('π Generating Turnstile token for sitekey:', sitekey); + const startTime = performance.now(); - if (typeof window !== 'undefined' && window.navigator) { - console.log('π§ UA:', window.navigator.userAgent, 'Platform:', window.navigator.platform); + try { + const { sitekey, token: preGeneratedToken } = await Utils.obtainSitekeyAndToken(); + + if (!sitekey) { + throw new Error('No valid sitekey found'); } - const token = await Utils.generatePaintToken(sitekey); - if (token && token.length > 20) { - const elapsed = Math.round(Date.now() - startTime); + console.log('π Using sitekey:', sitekey); + + if (typeof window !== 'undefined' && window.navigator) { + console.log( + 'π§ UA:', + window.navigator.userAgent.substring(0, 50) + '...', + 'Platform:', + window.navigator.platform + ); + } + + let token = null; + + if ( + preGeneratedToken && + typeof preGeneratedToken === 'string' && + preGeneratedToken.length > 20 + ) { + console.log('β»οΈ Reusing pre-generated Turnstile token'); + token = preGeneratedToken; + } else { + if (isTokenValid()) { + console.log('β»οΈ Using existing cached token (from previous session)'); + token = turnstileToken; + } else { + console.log('π Generating new token with executeTurnstile...'); + token = await Utils.executeTurnstile(sitekey, 'paint'); + if (token) setTurnstileToken(token); + } + } + + if (token && typeof token === 'string' && token.length > 20) { + const elapsed = Math.round(performance.now() - startTime); console.log(`β Turnstile token generated successfully in ${elapsed}ms`); return token; } else { - throw new Error('Invalid or empty token received'); + throw new Error(`Invalid or empty token received - Length: ${token?.length || 0}`); } } catch (error) { - const elapsed = Math.round(Date.now() - startTime); - console.log(`β Turnstile token generation failed after ${elapsed}ms:`, error); + const elapsed = Math.round(performance.now() - startTime); + console.error(`β Turnstile token generation failed after ${elapsed}ms:`, error); throw error; } } @@ -1178,7 +1208,18 @@ try { const payload = JSON.parse(args[1].body); if (payload.t) { - console.log('β Turnstile Token Captured:', payload.t); + // π Debug log + console.log( + `πβ Turnstile Token Captured - Type: ${typeof payload.t}, Value: ${ + payload.t + ? typeof payload.t === 'string' + ? payload.t.length > 50 + ? payload.t.substring(0, 50) + '...' + : payload.t + : JSON.stringify(payload.t) + : 'null/undefined' + }, Length: ${payload.t?.length || 0}` + ); window.postMessage({ source: 'turnstile-capture', token: payload.t }, '*'); } } catch (_) { @@ -1279,8 +1320,7 @@ if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`; if (minutes > 0) return `${minutes}m ${seconds}s`; return `${seconds}s`; - }, - // Turnstile Generator Integration - Optimized with widget reuse and proper cleanup + }, // Turnstile Generator Integration - Optimized with widget reuse and proper cleanup turnstileLoaded: false, _turnstileContainer: null, _turnstileOverlay: null, @@ -1579,10 +1619,6 @@ }); }, - async generatePaintToken(sitekey) { - return this.executeTurnstile(sitekey, 'paint'); - }, - // Cleanup method for when the script is disabled/reloaded cleanupTurnstile() { if (this._turnstileWidgetId && window.turnstile?.remove) { @@ -1607,11 +1643,17 @@ this._lastSitekey = null; }, - detectSitekey(fallback = '0x4AAAAAABpqJe8FO0N84q0F') { + async obtainSitekeyAndToken(fallback = '0x4AAAAAABpqJe8FO0N84q0F') { // Cache sitekey to avoid repeated DOM queries if (this._cachedSitekey) { console.log('π Using cached sitekey:', this._cachedSitekey); - return this._cachedSitekey; + + return isTokenValid() + ? { + sitekey: this._cachedSitekey, + token: turnstileToken, + } + : { sitekey: this._cachedSitekey, token: null }; } // List of potential sitekeys to try @@ -1620,77 +1662,101 @@ '0x4AAAAAAAJ7xjKAp6Mt_7zw', // Alternative WPlace sitekey '0x4AAAAAADm5QWx6Ov2LNF2g', // Another common sitekey ]; + const trySitekey = async (sitekey, source) => { + if (!sitekey || sitekey.length < 10) return null; + + console.log(`π Testing sitekey from ${source}:`, sitekey); + const token = await this.executeTurnstile(sitekey); + + if (token && token.length >= 20) { + console.log(`β Valid token generated from ${source} sitekey`); + setTurnstileToken(token); + this._cachedSitekey = sitekey; + return { sitekey, token }; + } else { + console.log(`β Failed to get token from ${source} sitekey`); + return null; + } + }; try { - // Try to find sitekey in data attributes + // 1οΈβ£ data-sitekey attribute const sitekeySel = document.querySelector('[data-sitekey]'); if (sitekeySel) { const sitekey = sitekeySel.getAttribute('data-sitekey'); - if (sitekey && sitekey.length > 10) { - this._cachedSitekey = sitekey; - console.log('π Sitekey detected from data attribute:', sitekey); - return sitekey; + const result = await trySitekey(sitekey, 'data attribute'); + if (result) { + return result; } } - // Try turnstile element + // 2οΈβ£ Turnstile element const turnstileEl = document.querySelector('.cf-turnstile'); - if (turnstileEl?.dataset?.sitekey && turnstileEl.dataset.sitekey.length > 10) { - this._cachedSitekey = turnstileEl.dataset.sitekey; - console.log('π Sitekey detected from turnstile element:', this._cachedSitekey); - return this._cachedSitekey; + if (turnstileEl?.dataset?.sitekey) { + const sitekey = turnstileEl.dataset.sitekey; + const result = await trySitekey(sitekey, 'turnstile element'); + if (result) { + return result; + } } - // Try to find sitekey in meta tags + // 3οΈβ£ Meta tags const metaTags = document.querySelectorAll( 'meta[name*="turnstile"], meta[property*="turnstile"]' ); for (const meta of metaTags) { const content = meta.getAttribute('content'); - if (content && content.length > 10) { - this._cachedSitekey = content; - console.log('π Sitekey detected from meta tag:', this._cachedSitekey); - return this._cachedSitekey; + const result = await trySitekey(content, 'meta tag'); + if (result) { + return result; } } - // Try global variable - if ( - typeof window !== 'undefined' && - window.__TURNSTILE_SITEKEY && - window.__TURNSTILE_SITEKEY.length > 10 - ) { - this._cachedSitekey = window.__TURNSTILE_SITEKEY; - console.log('π Sitekey detected from global variable:', this._cachedSitekey); - return this._cachedSitekey; + // 4οΈβ£ Global variable + if (window.__TURNSTILE_SITEKEY) { + const result = await trySitekey(window.__TURNSTILE_SITEKEY, 'global variable'); + if (result) { + return result; + } } - // Try script tags for inline sitekey + // 5οΈβ£ Script tags const scripts = document.querySelectorAll('script'); for (const script of scripts) { const content = script.textContent || script.innerHTML; - const sitekeyMatch = content.match(/sitekey['":\s]+(['"0-9a-zA-X_-]{20,})/i); - if (sitekeyMatch && sitekeyMatch[1] && sitekeyMatch[1].length > 10) { - this._cachedSitekey = sitekeyMatch[1].replace(/['"]/g, ''); - console.log('π Sitekey detected from script content:', this._cachedSitekey); - return this._cachedSitekey; + const match = content.match( + /(?:sitekey|data-sitekey)['"\s\[\]:\=\(]*['"]?([0-9a-zA-Z_-]{20,})['"]?/i + ); + if (match && match[1]) { + const extracted = match[1].replace(/['"]/g, ''); + const result = await trySitekey(extracted, 'script content'); + if (result) { + return result; + } } } - // If no sitekey found through detection, try the known working sitekeys - console.log('π No sitekey detected, trying known working sitekeys...'); + // 6οΈβ£ Known potential sitekeys + console.log('π Testing known potential sitekeys...'); for (const testSitekey of potentialSitekeys) { - console.log('π Trying sitekey:', testSitekey); - this._cachedSitekey = testSitekey; - return testSitekey; + const result = await trySitekey(testSitekey, 'known list'); + if (result) { + return result; + } } } catch (error) { - console.warn('Error detecting sitekey:', error); + console.warn('β οΈ Error during sitekey detection:', error); } - console.log('π Using fallback sitekey:', fallback); - this._cachedSitekey = fallback; - return fallback; + // 7οΈβ£ Fallback + console.log('π§ Trying fallback sitekey:', fallback); + const fallbackResult = await trySitekey(fallback, 'fallback'); + if (fallbackResult) { + return fallbackResult; + } + + console.error('β No working sitekey or token found.'); + return { sitekey: null, token: null }; }, createElement: (tag, props = {}, children = []) => { @@ -1892,11 +1958,15 @@ }, resolveColor(targetRgb, availableColors, exactMatch = false) { - if (!availableColors || availableColors.length === 0) return { id: null, rgb: targetRgb }; + if (!availableColors || availableColors.length === 0) + return { + id: null, + rgb: targetRgb, + }; - const cacheKey = `${targetRgb[0]},${targetRgb[1]},${targetRgb[2]}|${ - state.colorMatchingAlgorithm - }|${state.enableChromaPenalty ? 'c' : 'nc'}|${state.chromaPenaltyWeight}|${exactMatch ? 'exact' : 'closest'}`; + const cacheKey = `${targetRgb[0]},${targetRgb[1]},${targetRgb[2]}|${state.colorMatchingAlgorithm}|${ + state.enableChromaPenalty ? 'c' : 'nc' + }|${state.chromaPenaltyWeight}|${exactMatch ? 'exact' : 'closest'}`; if (colorCache.has(cacheKey)) return colorCache.get(cacheKey); @@ -2049,7 +2119,10 @@ extractAvailableColors: () => { const colorElements = document.querySelectorAll('.tooltip button[id^="color-"]'); - + if (colorElements.length === 0) { + console.log('β No color elements found on page'); + return null; + } // Separate available and unavailable colors const availableColors = []; const unavailableColors = []; @@ -2089,7 +2162,9 @@ console.log('\n--- AVAILABLE COLORS ---'); availableColors.forEach((color, index) => { console.log( - `${index + 1}. ID: ${color.id}, Name: "${color.name}", RGB: (${color.rgb[0]}, ${color.rgb[1]}, ${color.rgb[2]})` + `${ + index + 1 + }. ID: ${color.id}, Name: "${color.name}", RGB: (${color.rgb[0]}, ${color.rgb[1]}, ${color.rgb[2]})` ); }); } @@ -2098,7 +2173,9 @@ console.log('\n--- UNAVAILABLE COLORS ---'); unavailableColors.forEach((color, index) => { console.log( - `${index + 1}. ID: ${color.id}, Name: "${color.name}", RGB: (${color.rgb[0]}, ${color.rgb[1]}, ${color.rgb[2]}) [LOCKED]` + `${ + index + 1 + }. ID: ${color.id}, Name: "${color.name}", RGB: (${color.rgb[0]}, ${color.rgb[1]}, ${color.rgb[2]}) [LOCKED]` ); }); } @@ -2993,6 +3070,7 @@ .querySelector('#unselectPaidBtn') ?.addEventListener('click', () => unselectAllPaidColors()); } + async function handleCaptcha() { const startTime = performance.now(); @@ -3005,7 +3083,12 @@ // Generator mode (pure) or Hybrid mode - try generator first try { // Use optimized token generation with automatic sitekey detection - const sitekey = Utils.detectSitekey(); + const { sitekey, token: preGeneratedToken } = await Utils.obtainSitekeyAndToken(); + + if (!sitekey) { + throw new Error('No valid sitekey found'); + } + console.log('π Generating Turnstile token for sitekey:', sitekey); console.log( 'π§ UA:', @@ -3019,8 +3102,32 @@ await Utils.loadTurnstile(); } - const token = await Utils.generatePaintToken(sitekey); + let token = null; + // β Reuse pre-generated token if available and valid + if ( + preGeneratedToken && + typeof preGeneratedToken === 'string' && + preGeneratedToken.length > 20 + ) { + console.log('β»οΈ Reusing pre-generated token from sitekey detection phase'); + token = preGeneratedToken; + } + // β Or use globally cached token if still valid + else if (isTokenValid()) { + console.log('β»οΈ Using existing cached token (from previous operation)'); + token = turnstileToken; + } + // β Otherwise generate a new one + else { + console.log('π No valid pre-generated or cached token, creating new one...'); + token = await Utils.executeTurnstile(sitekey, 'paint'); + if (token) { + setTurnstileToken(token); + } + } + + // π Debug log console.log( `π Token received - Type: ${typeof token}, Value: ${ token @@ -3033,6 +3140,7 @@ }, Length: ${token?.length || 0}` ); + // β Final validation if (typeof token === 'string' && token.length > 20) { const duration = Math.round(performance.now() - startTime); console.log(`β Turnstile token generated successfully in ${duration}ms`); @@ -3371,7 +3479,9 @@ z-index: 99999; color: ${theme.text || 'white'}; font-family: ${theme.fontFamily || "'Segoe UI', Tahoma, Geneva, Verdana, sans-serif"}; - box-shadow: ${theme.boxShadow || '0 20px 40px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.1)'}; + box-shadow: ${ + theme.boxShadow || '0 20px 40px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.1)' + }; backdrop-filter: ${theme.backdropFilter || 'blur(10px)'}; overflow: hidden; animation: settingsSlideIn 0.4s ease-out; @@ -3407,9 +3517,15 @@
Generator mode creates tokens automatically. Hybrid mode falls back to manual when generator fails. Manual mode only uses pixel placement. @@ -3429,7 +3545,9 @@