diff --git a/Auto-Image.js b/Auto-Image.js index 049bad5..0d0b9d6 100644 --- a/Auto-Image.js +++ b/Auto-Image.js @@ -1,4 +1,17 @@ ; (async () => { + // Base URL configuration - checks localStorage first, falls back to GitHub + const getBaseUrl = () => { + try { + const customBaseUrl = localStorage.getItem('wplace-autobot-base-url'); + if (customBaseUrl) { + return customBaseUrl.endsWith('/') ? customBaseUrl.slice(0, -1) : customBaseUrl; + } + } catch (e) { + console.warn('Could not access localStorage for base URL:', e); + } + return 'https://raw.githubusercontent.com/Wplace-AutoBot/WPlace-AutoBOT/main'; + }; + // CONFIGURATION CONSTANTS const CONFIG = { COOLDOWN_DEFAULT: 31000, @@ -283,8 +296,8 @@ function applyTheme() { return loadedTranslations[language]; } - // Load translations from CDN - const url = `https://staninna.github.io/WPlace-AutoBOT/decoupled-translations/lang/${language}.json`; + // Load translations using base URL (checks localStorage, falls back to GitHub) + const url = `${getBaseUrl()}/decoupled-translations/lang/${language}.json`; const maxRetries = 3; const baseDelay = 1000; // 1 second @@ -2729,10 +2742,20 @@ function applyTheme() { // Link external CSS files const cssLink = document.createElement('link'); cssLink.rel = 'stylesheet'; - cssLink.href = 'https://staninna.github.io/WPlace-AutoBOT/decoupled-css/auto-image-styles.css'; // TODO: Before merge change to https://raw.githubusercontent.com/Wplace-AutoBot/WPlace-AutoBOT/refs/heads/main/auto-image-styles.css + cssLink.href = `${getBaseUrl()}/auto-image-styles.css`; cssLink.setAttribute('data-wplace-theme', 'true'); document.head.appendChild(cssLink); + // Dynamically load theme CSS files using base URL + const themeFiles = ['classic.css', 'classic-light.css', 'neon.css']; + themeFiles.forEach(themeFile => { + const themeLink = document.createElement('link'); + themeLink.rel = 'stylesheet'; + themeLink.href = `${getBaseUrl()}/themes/${themeFile}`; + themeLink.setAttribute('data-wplace-theme-file', themeFile); + document.head.appendChild(themeLink); + }); + const container = document.createElement("div") container.id = "wplace-image-bot-container" container.innerHTML = ` diff --git a/auto-image-styles.css b/auto-image-styles.css index e3fecf3..2a44553 100644 --- a/auto-image-styles.css +++ b/auto-image-styles.css @@ -7,10 +7,8 @@ /* Theme tokens (CSS vars) */ /* ========================= */ -/* Import theme files - classic is default */ -@import url('https://staninna.github.io/WPlace-AutoBOT/decoupled-css/themes/classic.css'); -@import url('https://staninna.github.io/WPlace-AutoBOT/decoupled-css/themes/classic-light.css'); -@import url('https://staninna.github.io/WPlace-AutoBOT/decoupled-css/themes/neon.css'); +/* Theme files are now loaded dynamically via JavaScript using the base URL from localStorage */ +/* See Auto-Image.js lines 2749-2757 for dynamic theme loading implementation */ /* Default :root CSS variables for 100% classic theme compliance */ /* These ensure the bot works perfectly even if theme files fail to load */