convertor/public/theme-init.js
2025-12-08 17:26:57 +02:00

21 lines
607 B
JavaScript

// public/theme-init.js
// Runs on every page and applies the saved theme *before* the page renders.
(function () {
var STORAGE_KEY = "convertx-theme";
try {
var theme = localStorage.getItem(STORAGE_KEY);
// default to light if nothing stored or value is invalid
if (theme === "dark") {
document.documentElement.setAttribute("data-theme", "dark");
} else {
document.documentElement.removeAttribute("data-theme");
}
} catch (_e) {
// If localStorage is blocked, just fall back to light theme
document.documentElement.removeAttribute("data-theme");
}
})();