diff --git a/Extension/background.js b/Extension/background.js index 07936d3..b83addf 100644 --- a/Extension/background.js +++ b/Extension/background.js @@ -48,7 +48,7 @@ async function executeLocalScript(scriptName, tabId) { } else { scriptUrl = chrome.runtime.getURL(`scripts/${scriptName}`); } - + const response = await fetch(scriptUrl); if (!response.ok) { @@ -67,38 +67,38 @@ async function executeLocalScript(scriptName, tabId) { world: "MAIN", // Key: executes in page context, not extension context func: (code, name, themeCSS, languages) => { console.log(`%cš Executing ${name}...`, 'color: #4ade80; font-weight: bold; font-size: 14px;'); - + // Create detailed resource report console.group(`%cš WPlace AutoBOT Resource Report for ${name}`, 'color: #3b82f6; font-weight: bold; font-size: 16px;'); - + // Debug: Log what resources we received console.log(`%cš¦ Raw Resources Received:`, 'color: #8b5cf6; font-weight: bold;'); console.log(` - Themes object:`, themeCSS); console.log(` - Languages object:`, languages); console.log(` - Theme count: ${Object.keys(themeCSS || {}).length}`); console.log(` - Language count: ${Object.keys(languages || {}).length}`); - + // Inject CSS themes if available if (themeCSS && Object.keys(themeCSS).length > 0) { console.group(`%cšØ Theme Processing`, 'color: #8b5cf6; font-weight: bold;'); console.log(`%cš Loading ${Object.keys(themeCSS).length} theme files from extension local storage...`, 'color: #8b5cf6;'); - + // Create a global themes object window.AUTOBOT_THEMES = themeCSS; - + // Log detailed theme information Object.entries(themeCSS).forEach(([filename, content]) => { console.log(`%cš Theme File: ${filename}`, 'color: #8b5cf6; font-weight: bold;'); console.log(` š Size: ${content.length.toLocaleString()} characters`); console.log(` š Source: Extension local file (chrome-extension://)`); console.log(` š Full path: themes/${filename}`); - + // Show first few lines as preview const preview = content.substring(0, 200).split('\\n').slice(0, 3).join('\\n'); console.log(` š Preview: ${preview}${content.length > 200 ? '...' : ''}`); console.log(` ā Status: Loaded successfully`); }); - + // Inject auto-image-styles.css if available if (themeCSS['auto-image-styles.css']) { const autoImageContent = themeCSS['auto-image-styles.css']; @@ -106,7 +106,7 @@ async function executeLocalScript(scriptName, tabId) { styleElement.id = 'autobot-auto-image-styles'; styleElement.textContent = autoImageContent; document.head.appendChild(styleElement); - + console.log(`%c⨠AUTO-INJECTED: auto-image-styles.css`, 'color: #10b981; font-weight: bold;'); console.log(` š Injected size: ${autoImageContent.length.toLocaleString()} characters`); console.log(` š Source: Extension local file`); @@ -122,14 +122,14 @@ async function executeLocalScript(scriptName, tabId) { console.log(` š Expected files: auto-image-styles.css, acrylic.css, classic.css, etc.`); window.AUTOBOT_THEMES = {}; } - + // Inject language data if available if (languages && Object.keys(languages).length > 0) { console.group(`%cš Language Processing`, 'color: #06b6d4; font-weight: bold;'); console.log(`%cš Loading ${Object.keys(languages).length} language files from extension local storage...`, 'color: #06b6d4;'); - + window.AUTOBOT_LANGUAGES = languages; - + // Log detailed language information Object.entries(languages).forEach(([filename, content]) => { console.log(`%cš Language File: ${filename}`, 'color: #06b6d4; font-weight: bold;'); @@ -137,18 +137,18 @@ async function executeLocalScript(scriptName, tabId) { console.log(` š Keys count: ${Object.keys(content).length.toLocaleString()}`); console.log(` š Source: Extension local file (chrome-extension://)`); console.log(` š Full path: lang/${filename}`); - + // Show some sample keys const sampleKeys = Object.keys(content).slice(0, 5); console.log(` š Sample keys: ${sampleKeys.join(', ')}${Object.keys(content).length > 5 ? '...' : ''}`); console.log(` ā Status: Loaded successfully`); }); - + // Helper function to get language data with detailed logging - window.getLanguage = function(lang = 'en') { + window.getLanguage = function (lang = 'en') { const langFile = lang + '.json'; const result = window.AUTOBOT_LANGUAGES[langFile] || window.AUTOBOT_LANGUAGES['en.json'] || {}; - + console.group(`%cš¤ Language Access: ${lang.toUpperCase()}`, 'color: #06b6d4; font-weight: bold;'); console.log(` š Requested: ${lang}`); console.log(` š File: ${langFile}`); @@ -157,10 +157,10 @@ async function executeLocalScript(scriptName, tabId) { console.log(` ā Success: ${window.AUTOBOT_LANGUAGES[langFile] ? 'Found exact match' : 'Fallback to English'}`); console.log(` š Data preview:`, result); console.groupEnd(); - + return result; }; - + console.log(`%cš¤ Available languages: ${Object.keys(languages).map(f => f.replace('.json', '')).join(', ')}`, 'color: #06b6d4;'); console.groupEnd(); } else { @@ -168,16 +168,16 @@ async function executeLocalScript(scriptName, tabId) { console.log(` š Expected source: Extension local files`); console.log(` š Expected files: en.json, de.json, fr.json, etc.`); window.AUTOBOT_LANGUAGES = {}; - window.getLanguage = function() { + window.getLanguage = function () { console.warn(`%cā ļø getLanguage() called but no languages available`, 'color: #f59e0b;'); - return {}; + return {}; }; } - + // Helper function to apply theme with detailed logging - window.applyTheme = function(themeName) { + window.applyTheme = function (themeName) { console.group(`%cšØ Theme Application: ${themeName}`, 'color: #8b5cf6; font-weight: bold;'); - + if (!window.AUTOBOT_THEMES || Object.keys(window.AUTOBOT_THEMES).length === 0) { console.error(`%cā No themes available in extension`, 'color: #ef4444; font-weight: bold;'); console.log(` š Expected source: Extension local files`); @@ -185,38 +185,38 @@ async function executeLocalScript(scriptName, tabId) { console.groupEnd(); return false; } - + const themeFile = themeName + '.css'; console.log(` š Requested theme: ${themeName}`); console.log(` š Looking for file: ${themeFile}`); console.log(` š Available themes: ${Object.keys(window.AUTOBOT_THEMES).join(', ')}`); - + if (window.AUTOBOT_THEMES[themeFile]) { const themeContent = window.AUTOBOT_THEMES[themeFile]; - + // Remove existing theme const existing = document.getElementById('autobot-theme'); if (existing) { console.log(` šļø Removing previous theme element`); existing.remove(); } - + // Apply new theme const styleElement = document.createElement('style'); styleElement.id = 'autobot-theme'; styleElement.textContent = themeContent; document.head.appendChild(styleElement); - + console.log(`%cā Theme applied successfully: ${themeName}`, 'color: #10b981; font-weight: bold;'); console.log(` š Content size: ${themeContent.length.toLocaleString()} characters`); console.log(` š Source: Extension local file`); console.log(` šÆ Target:
as