Files
training-software/frontend/public/theme.js
Paperclip CTO 4a46c14857
All checks were successful
CI / lint (push) Successful in 10s
CI / test (push) Successful in 23s
CI / build-container (push) Successful in 8s
feat(frontend): add theming, branding sync, and improved frontend error UX
2026-05-19 09:09:04 +02:00

35 lines
952 B
JavaScript

(function () {
"use strict";
const STORAGE_KEY = "ui_theme";
const root = document.documentElement;
const button = document.getElementById("theme-toggle");
function setTheme(theme) {
root.setAttribute("data-theme", theme);
try {
localStorage.setItem(STORAGE_KEY, theme);
} catch (_) {}
if (button) {
button.textContent = theme === "dark" ? "Light Mode" : "Dark Mode";
}
}
function getInitialTheme() {
try {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored === "dark" || stored === "light") return stored;
} catch (_) {}
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
setTheme(getInitialTheme());
if (button) {
button.addEventListener("click", function () {
const current = root.getAttribute("data-theme") === "dark" ? "dark" : "light";
setTheme(current === "dark" ? "light" : "dark");
});
}
})();