| 64 | // --------------------------------------------------------------------------- |
| 65 | |
| 66 | function getInitialTheme() { |
| 67 | try { |
| 68 | const stored = |
| 69 | localStorage.getItem("td-theme") ?? localStorage.getItem("ts-theme"); |
| 70 | if (stored === "light" || stored === "dark") return stored; |
| 71 | } catch { |
| 72 | /* storage unavailable */ |
| 73 | } |
| 74 | return window.matchMedia?.("(prefers-color-scheme: light)").matches ? "light" : "dark"; |
| 75 | } |
| 76 | |
| 77 | function applyTheme(theme) { |
| 78 | document.documentElement.setAttribute("data-theme", theme); |