2025-02-16 20:03:30 +01:00
|
|
|
const button = document.getElementById("theme");
|
|
|
|
const classes = document.documentElement.classList;
|
|
|
|
|
2025-02-17 01:51:01 +01:00
|
|
|
function button_refresh() {
|
|
|
|
button.innerHTML = theme_get();
|
2025-02-16 22:03:58 +01:00
|
|
|
}
|
2025-02-17 01:51:01 +01:00
|
|
|
function theme_get() {
|
2025-02-16 22:03:58 +01:00
|
|
|
return classes.contains("dark")?"dark":"light";
|
2025-02-16 20:03:30 +01:00
|
|
|
}
|
2025-02-17 01:51:01 +01:00
|
|
|
function theme_read() {
|
|
|
|
const theme = localStorage.getItem("theme");
|
|
|
|
if (theme) {
|
|
|
|
theme_set(theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function theme_set(theme) {
|
|
|
|
if (theme == "dark") {
|
|
|
|
classes.add("dark");
|
|
|
|
}
|
|
|
|
button_refresh();
|
|
|
|
}
|
|
|
|
function theme_toggle() {
|
|
|
|
classes.toggle("dark");
|
|
|
|
button_refresh();
|
|
|
|
theme_write();
|
|
|
|
}
|
|
|
|
function theme_write() {
|
|
|
|
localStorage.setItem("theme", theme_get());
|
|
|
|
}
|
2025-02-16 20:03:30 +01:00
|
|
|
|
|
|
|
button.addEventListener("click", () => {
|
2025-02-17 01:51:01 +01:00
|
|
|
theme_toggle();
|
2025-02-16 20:03:30 +01:00
|
|
|
});
|
|
|
|
|
2025-02-17 01:51:01 +01:00
|
|
|
theme_read();
|