24 lines
No EOL
743 B
JavaScript
24 lines
No EOL
743 B
JavaScript
const basePath = "/assets/css";
|
|
const themeToggle = document.getElementById("theme-toggle");
|
|
const themeStylesheet = document.getElementById("custom");
|
|
|
|
const themes = [
|
|
{ name: "system", file: "default/system.css" },
|
|
{ name: "citrus", file: "citrus/citrus.css" },
|
|
];
|
|
|
|
let currentTheme = localStorage.getItem("theme") || themes[0].name;
|
|
setTheme(currentTheme);
|
|
|
|
function setTheme(themeName) {
|
|
const theme = themes.find(t => t.name === themeName);
|
|
if (theme) {
|
|
themeStylesheet.href = `${basePath}/${theme.file}`;
|
|
}
|
|
}
|
|
|
|
themeToggle.addEventListener("click", () => {
|
|
currentTheme = themes[(themes.findIndex(t => t.name === currentTheme) + 1) % themes.length].name;
|
|
setTheme(currentTheme);
|
|
localStorage.setItem("theme", currentTheme);
|
|
}); |