Reapply "Update urls && baseurl in localstorage"

This reverts commit f74e54458d.
This commit is contained in:
Staninna committed 2025-08-31 12:18:22 +02:00
1 parent 4ae1804c62
commit ef7431cf46
2 files changed
+28 -7

No files matched your search

+26 -3
View File
@@ -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 = `
+2 -4
View File
@@ -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 */