cv.marc/in/script/main.js

32 lines
713 B
JavaScript
Raw Normal View History

2025-02-16 20:03:30 +01:00
const button = document.getElementById("theme");
2025-02-17 01:51:01 +01:00
function theme_get() {
2025-02-18 00:01:39 +01:00
return document.documentElement.getAttribute("data-theme");
2025-02-16 20:03:30 +01:00
}
2025-02-18 00:01:39 +01:00
function theme_load() {
2025-02-17 01:51:01 +01:00
const theme = localStorage.getItem("theme");
if (theme) {
theme_set(theme);
}
}
function theme_set(theme) {
2025-02-18 00:01:39 +01:00
document.documentElement.setAttribute("data-theme", theme);
button.innerHTML = theme;
theme_write(theme);
}
function theme_swap(theme) {
return theme === "dark" ? "light" : "dark";
2025-02-17 01:51:01 +01:00
}
function theme_toggle() {
2025-02-18 00:01:39 +01:00
theme_set(theme_swap(theme_get()));
2025-02-17 01:51:01 +01:00
}
2025-02-18 00:01:39 +01:00
function theme_write(theme) {
localStorage.setItem("theme", theme);
2025-02-17 01:51:01 +01:00
}
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-18 00:01:39 +01:00
theme_load();