26 lines
906 B
JavaScript
26 lines
906 B
JavaScript
(function () {
|
|
const KEY = "frenchJourney.theme";
|
|
const root = document.documentElement;
|
|
|
|
function apply(theme) {
|
|
root.dataset.theme = theme;
|
|
localStorage.setItem(KEY, theme);
|
|
const button = document.querySelector("[data-theme-toggle]");
|
|
if (button) {
|
|
const dark = theme === "dark";
|
|
button.textContent = dark ? "Light" : "Dark";
|
|
button.setAttribute("aria-pressed", String(dark));
|
|
}
|
|
}
|
|
|
|
const saved = localStorage.getItem(KEY);
|
|
const preferred = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
apply(saved || preferred);
|
|
|
|
window.addEventListener("DOMContentLoaded", () => {
|
|
const button = document.querySelector("[data-theme-toggle]");
|
|
if (!button) return;
|
|
button.onclick = () => apply(root.dataset.theme === "dark" ? "light" : "dark");
|
|
apply(root.dataset.theme || "light");
|
|
});
|
|
})();
|