Files
wrapped/app/static/js/theme.js
T
inecs 806f2bdb1b
devops-tools/wrapped/wrapped-build/pipeline/head There was a failure building this commit
Выпущен 0.1.3: UX convenience pack, unwrap/admin polish и cache-bust статики.
Добавлены Share/QR PNG, zip all, size meter, PWA-manifest, системная тема и haptic на copy; улучшены success/unwrap и статистика админки (EN/RU).
2026-07-29 11:33:21 +03:00

38 lines
1.1 KiB
JavaScript

(() => {
const KEY = "wrapped.theme";
function systemTheme() {
return window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
}
function preferred() {
const stored = localStorage.getItem(KEY);
if (stored === "light" || stored === "dark") return stored;
return systemTheme();
}
function apply(theme) {
document.documentElement.setAttribute("data-theme", theme);
const sun = document.getElementById("theme-icon-sun");
const moon = document.getElementById("theme-icon-moon");
if (sun && moon) {
sun.classList.toggle("hidden", theme !== "light");
moon.classList.toggle("hidden", theme !== "dark");
}
}
function toggle() {
const current = document.documentElement.getAttribute("data-theme") || preferred();
const next = current === "dark" ? "light" : "dark";
localStorage.setItem(KEY, next);
apply(next);
}
apply(preferred());
document.addEventListener("DOMContentLoaded", () => {
apply(preferred());
const btn = document.getElementById("theme-toggle");
if (btn) btn.addEventListener("click", toggle);
});
})();