webbed-site/theme.js

26 lines
904 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';
} else if (theme === 'fishcake') {
2024-09-26 12:47:17 -05:00
document.getElementById('switcher-id').href = '/themes/fishcake.css';
} // when adding new themes, be sure to also add it to /templates/alt-sidebar.html and style.css under "switch" //
localStorage.setItem('style', theme);
}