-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (25 loc) · 950 Bytes
/
Copy pathscript.js
File metadata and controls
29 lines (25 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
document.addEventListener("DOMContentLoaded", () => {
const body = document.body;
const toggle = document.querySelector(".theme-toggle");
const storedTheme = localStorage.getItem("theme");
const systemPrefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
const initialTheme = storedTheme || (systemPrefersDark ? "dark" : "light");
const applyTheme = (theme) => {
body.dataset.theme = theme;
localStorage.setItem("theme", theme);
};
document.title = "Sinter Studio";
applyTheme(initialTheme);
if (toggle) {
toggle.addEventListener("click", () => {
const nextTheme = body.dataset.theme === "dark" ? "light" : "dark";
toggle.classList.remove("is-animating");
void toggle.offsetWidth;
toggle.classList.add("is-animating");
applyTheme(nextTheme);
});
toggle.addEventListener("animationend", () => {
toggle.classList.remove("is-animating");
});
}
});