cv.marc/in/script/main.js
Marc Beninca 05cbc1948a
All checks were successful
/ job (push) Successful in 1m14s
js/toggle
2025-04-17 09:55:28 +02:00

42 lines
906 B
JavaScript

const buttons = ["link", "swap"];
// toggle buttons
for (let button of buttons) {
document.getElementById(button).addEventListener("click", () => {
document.body.classList.toggle(button);
});
}
// theme
const button = document.getElementById("theme");
function theme_get() {
return document.documentElement.getAttribute("data-theme");
}
function theme_load() {
const theme = localStorage.getItem("theme");
if (theme) {
theme_set(theme);
}
}
function theme_set(theme) {
document.documentElement.setAttribute("data-theme", theme);
theme_write(theme);
}
function theme_swap(theme) {
return theme === "dark" ? "light" : "dark";
}
function theme_toggle() {
theme_set(theme_swap(theme_get()));
}
function theme_write(theme) {
localStorage.setItem("theme", theme);
}
button.addEventListener("click", () => {
theme_toggle();
});
theme_load();