static/theme.js
raw ·
blame ·
history
// Applies the saved (or system-preferred) theme before first paint, so it is
// in place before the stylesheet renders and there is no flash of the wrong
// theme. Kept in a static file rather than inline so the strict page CSP
// (script-src 'self') allows it. app.js handles switching and persistence.
(function () {
try {
var t = localStorage.getItem("theme");
if (t !== "light" && t !== "dark") {
t = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
document.documentElement.setAttribute("data-theme", t);
} catch (e) { /* private mode / storage disabled: fall back to CSS default */ }
})();