From 13af6f927925164acf0fa458d279ca8f262da2f4 Mon Sep 17 00:00:00 2001 From: CodeDevMLH Date: Mon, 16 Dec 2024 01:59:30 +0100 Subject: [PATCH] fixes --- seasonals.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/seasonals.js b/seasonals.js index c3eaa77..6bd060b 100644 --- a/seasonals.js +++ b/seasonals.js @@ -1,7 +1,7 @@ // theme-configs.js const automateThemeSelection = false; // Set to false to disable automatic theme selection based on the current month -const defaultTheme = 'snowflakes'; // The theme to use if automatic theme selection is disabled +const defaultTheme = 'snowflakes'; // The theme to use if automatic theme selection is disabled // theme configurations const themeConfigs = { @@ -59,56 +59,73 @@ function determineCurrentTheme() { if (month >= 5 && month <= 7) return 'summer'; if (month >= 8 && month <= 10) return 'autumn'; - return ''; // Fallback (nothing) + return defaultTheme; // Fallback (nothing) } // load theme csss function loadThemeCSS(cssPath) { + if (!cssPath) return; + const link = document.createElement('link'); link.rel = 'stylesheet'; link.href = cssPath; + + link.onerror = () => { + console.error(`Failed to load CSS: ${cssPath}`); + }; + document.head.appendChild(link); console.log(`CSS file "${cssPath}" loaded.`); } // load theme js function loadThemeJS(jsPath) { + if (!jsPath) return; + const script = document.createElement('script'); script.src = jsPath; + + script.onerror = () => { + console.error(`Failed to load JS: ${jsPath}`); + }; + document.body.appendChild(script); console.log(`JS file "${jsPath}" loaded.`); } // update theme container class name function updateThemeContainer(containerClass) { - const container = document.querySelector('.seasonal-container'); + const container = document.querySelector('.seasonals-container'); if (!container) { - console.error('No element with the class "seasonal-container" found.'); + console.error('No element with the class "seasonals-container" found.'); return; } container.className = containerClass; + console.log(`Seasonals-Container class updated to "${containerClass}".`); } // initialize theme function initializeTheme() { + let currentTheme; if (!automateThemeSelection) { - const currentTheme = defaultTheme; + currentTheme = defaultTheme; } else { - const currentTheme = determineCurrentTheme(); + currentTheme = determineCurrentTheme(); } - const theme = themeConfigs[currentTheme]; + console.log(`Selected theme: ${currentTheme}`); + const theme = themeConfigs[currentTheme]; + if (!theme) { console.error(`Theme "${currentTheme}" not found.`); return; } + updateThemeContainer(theme.containerClass); if (theme.css) loadThemeCSS(theme.css); if (theme.js) loadThemeJS(theme.js); - updateThemeContainer(theme.containerClass); - console.log(`Theme "${currentTheme}" loaded.`); }