40 lines
837 B
JavaScript
40 lines
837 B
JavaScript
// link
|
|
|
|
const link = document.getElementById("link");
|
|
|
|
link.addEventListener("click", () => {
|
|
document.body.classList.toggle("link");
|
|
});
|
|
|
|
// 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();
|