Domain Name: Marc Beninca 馃敆
marc.beninca.link
1// buttons
2
3const buttons = ["debug", "link"];
4
5for (let button of buttons) {
6 document.getElementById(button).addEventListener("click", () => {
7 document.body.classList.toggle(button);
8 });
9}
10
11// theme
12
13let theme;
14
15function theme_get() {
16 theme = localStorage.getItem("theme");
17 if (! theme) {
18 if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
19 theme = "dark";
20 } else {
21 theme = "light";
22 }
23 }
24 theme_set();
25}
26
27function theme_set() {
28 document.documentElement.setAttribute("data-theme", theme);
29 localStorage.setItem("theme", theme);
30}
31
32function theme_swap() {
33 theme = theme === "light" ? "dark" : "light";
34 theme_set();
35}
36
37document.getElementById("theme").addEventListener("click", () => {
38 theme_swap();
39});
40
41theme_get();