in
This commit is contained in:
parent
0d0310cea7
commit
dc43aee71a
26 changed files with 0 additions and 0 deletions
31
in/script/main.js
Normal file
31
in/script/main.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
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);
|
||||
button.innerHTML = 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();
|
Loading…
Add table
Add a link
Reference in a new issue