parent
bb08ce9457
commit
d51809e39b
34 changed files with 4834 additions and 0 deletions
37
in/script/main.js
Normal file
37
in/script/main.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const buttons = ["item", "link", "swap"];
|
||||
|
||||
for (let button of buttons) {
|
||||
document.getElementById(button).addEventListener("click", () => {
|
||||
document.body.classList.toggle(button);
|
||||
});
|
||||
}
|
||||
|
||||
let theme
|
||||
|
||||
function theme_get() {
|
||||
theme = localStorage.getItem("theme");
|
||||
if (! theme) {
|
||||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||
theme = "dark";
|
||||
} else {
|
||||
theme = "light";
|
||||
}
|
||||
}
|
||||
theme_set()
|
||||
}
|
||||
|
||||
function theme_set() {
|
||||
document.documentElement.setAttribute("data-theme", theme);
|
||||
localStorage.setItem("theme", theme);
|
||||
}
|
||||
|
||||
function theme_swap() {
|
||||
theme = theme === "light" ? "dark" : "light";
|
||||
theme_set();
|
||||
}
|
||||
|
||||
document.getElementById("theme").addEventListener("click", () => {
|
||||
theme_swap();
|
||||
});
|
||||
|
||||
theme_get()
|
Loading…
Add table
Add a link
Reference in a new issue