webbed-site/theme.js

26 lines
900 B
JavaScript
Raw Normal View History

const storedStyle = localStorage.getItem('style');
if (!storedStyle) {
setTheme('green');
} else {
setTheme(storedStyle);
}
const switches = document.getElementsByClassName('switch');
for (const el of switches) {
el.addEventListener('click', () => {
setTheme(el.dataset.theme);
});
}
function setTheme(theme) {
if (theme === 'peach') {
2024-09-26 12:47:17 -05:00
document.getElementById('switcher-id').href = '/themes/peach.css';
} else if (theme === 'moon') {
2024-09-26 12:47:17 -05:00
document.getElementById('switcher-id').href = '/themes/moon.css';
} else if (theme === 'sakura') {
2024-09-26 12:47:17 -05:00
document.getElementById('switcher-id').href = '/themes/sakura.css';
2024-12-12 20:47:37 -06:00
} else if (theme === 'honey') {
document.getElementById('switcher-id').href = '/themes/honey.css';
} // when adding new themes, be sure to also add it to /includes/layout/sidebar.html and style.css under "switch" //
localStorage.setItem('style', theme);
}