This commit is contained in:
MLH
2024-12-16 01:59:30 +01:00
parent c0ee5f0302
commit 13af6f9279

View File

@ -1,7 +1,7 @@
// theme-configs.js // theme-configs.js
const automateThemeSelection = false; // Set to false to disable automatic theme selection based on the current month 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 // theme configurations
const themeConfigs = { const themeConfigs = {
@ -59,56 +59,73 @@ function determineCurrentTheme() {
if (month >= 5 && month <= 7) return 'summer'; if (month >= 5 && month <= 7) return 'summer';
if (month >= 8 && month <= 10) return 'autumn'; if (month >= 8 && month <= 10) return 'autumn';
return ''; // Fallback (nothing) return defaultTheme; // Fallback (nothing)
} }
// load theme csss // load theme csss
function loadThemeCSS(cssPath) { function loadThemeCSS(cssPath) {
if (!cssPath) return;
const link = document.createElement('link'); const link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.href = cssPath; link.href = cssPath;
link.onerror = () => {
console.error(`Failed to load CSS: ${cssPath}`);
};
document.head.appendChild(link); document.head.appendChild(link);
console.log(`CSS file "${cssPath}" loaded.`); console.log(`CSS file "${cssPath}" loaded.`);
} }
// load theme js // load theme js
function loadThemeJS(jsPath) { function loadThemeJS(jsPath) {
if (!jsPath) return;
const script = document.createElement('script'); const script = document.createElement('script');
script.src = jsPath; script.src = jsPath;
script.onerror = () => {
console.error(`Failed to load JS: ${jsPath}`);
};
document.body.appendChild(script); document.body.appendChild(script);
console.log(`JS file "${jsPath}" loaded.`); console.log(`JS file "${jsPath}" loaded.`);
} }
// update theme container class name // update theme container class name
function updateThemeContainer(containerClass) { function updateThemeContainer(containerClass) {
const container = document.querySelector('.seasonal-container'); const container = document.querySelector('.seasonals-container');
if (!container) { if (!container) {
console.error('No element with the class "seasonal-container" found.'); console.error('No element with the class "seasonals-container" found.');
return; return;
} }
container.className = containerClass; container.className = containerClass;
console.log(`Seasonals-Container class updated to "${containerClass}".`);
} }
// initialize theme // initialize theme
function initializeTheme() { function initializeTheme() {
let currentTheme;
if (!automateThemeSelection) { if (!automateThemeSelection) {
const currentTheme = defaultTheme; currentTheme = defaultTheme;
} else { } else {
const currentTheme = determineCurrentTheme(); currentTheme = determineCurrentTheme();
} }
const theme = themeConfigs[currentTheme]; console.log(`Selected theme: ${currentTheme}`);
const theme = themeConfigs[currentTheme];
if (!theme) { if (!theme) {
console.error(`Theme "${currentTheme}" not found.`); console.error(`Theme "${currentTheme}" not found.`);
return; return;
} }
updateThemeContainer(theme.containerClass);
if (theme.css) loadThemeCSS(theme.css); if (theme.css) loadThemeCSS(theme.css);
if (theme.js) loadThemeJS(theme.js); if (theme.js) loadThemeJS(theme.js);
updateThemeContainer(theme.containerClass);
console.log(`Theme "${currentTheme}" loaded.`); console.log(`Theme "${currentTheme}" loaded.`);
} }