theme.js javascript
45 lines 1.5 KB
Raw
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1 docs: MuseHub-first before ISR #74 — staging solidify NEXT Human 3 days ago
1 /** Landing theme toggle — preference only (not auth). Default is always dark. */
2 (function () {
3 // v2: ignore legacy stored preference so first paint stays dark by default.
4 var KEY = "overseer-landing-theme-v2";
5 var root = document.documentElement;
6
7 function preferred() {
8 try {
9 var stored = localStorage.getItem(KEY);
10 // Only honor an explicit user choice; ignore OS prefers-color-scheme.
11 if (stored === "light" || stored === "dark") return stored;
12 } catch (_e) {
13 /* file:// or blocked storage — fall through */
14 }
15 return "dark";
16 }
17
18 function apply(theme) {
19 root.setAttribute("data-theme", theme);
20 var btn = document.getElementById("theme-toggle");
21 if (!btn) return;
22 var next = theme === "dark" ? "light" : "dark";
23 btn.setAttribute("aria-label", "Switch to " + next + " mode");
24 btn.setAttribute("title", next === "light" ? "Light mode" : "Dark mode");
25 }
26
27 // Apply immediately so first paint is not light on light-preferring OSes.
28 apply(preferred());
29
30 document.addEventListener("DOMContentLoaded", function () {
31 apply(root.getAttribute("data-theme") || preferred());
32 var btn = document.getElementById("theme-toggle");
33 if (!btn) return;
34 btn.addEventListener("click", function () {
35 var current = root.getAttribute("data-theme") === "light" ? "light" : "dark";
36 var next = current === "dark" ? "light" : "dark";
37 apply(next);
38 try {
39 localStorage.setItem(KEY, next);
40 } catch (_e) {
41 /* ignore */
42 }
43 });
44 });
45 })();
File History 1 commit
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1 docs: MuseHub-first before ISR #74 — staging solidify NEXT Human 3 days ago