feat: add light theme toggle

This commit is contained in:
strsv committed 2026-11-06 08:17:03 +03:00
1 parent 448e7a723d
commit 2fcb29e3fe
8 files changed
+132 -13

No files matched your search

+22
View File
@@ -8,6 +8,7 @@ const STATUS_LABEL = {
ignore: "скрыта",
};
const PER_PAGE = 60;
const THEME_KEY = "sb.theme";
const state = {
view: "library",
@@ -141,6 +142,27 @@ function applyMaintenance(open) {
maintenanceToggle.addEventListener("click", () => applyMaintenance(!maintenanceOpen));
applyMaintenance(maintenanceOpen);
const themeToggle = $("#themeToggle");
function syncThemeButton() {
const light = document.documentElement.dataset.theme === "light";
themeToggle.title = light ? "Тёмная тема" : "Светлая тема";
themeToggle.setAttribute("aria-label", themeToggle.title);
themeToggle.setAttribute("aria-pressed", String(light));
}
themeToggle.addEventListener("click", () => {
const light = document.documentElement.dataset.theme === "light";
if (light) {
delete document.documentElement.dataset.theme;
} else {
document.documentElement.dataset.theme = "light";
}
try {
localStorage.setItem(THEME_KEY, light ? "dark" : "light");
} catch (_) {}
syncThemeButton();
});
syncThemeButton();
function esc(value) {
return String(value ?? "")
.replaceAll("&", "&")