mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-20 10:22:26 +08:00
28 lines
997 B
TypeScript
28 lines
997 B
TypeScript
const preference = localStorage.getItem("theme");
|
|
if (preference) {
|
|
if (preference === "dark") {
|
|
document.body.classList.add("theme-dark");
|
|
document.body.classList.remove("theme-light");
|
|
}
|
|
else {
|
|
document.body.classList.remove("theme-dark");
|
|
document.body.classList.add("theme-light");
|
|
}
|
|
}
|
|
|
|
export default function setupThemeSelector() {
|
|
const themeSwitch: HTMLInputElement = document.querySelector(".theme-selection input")!;
|
|
// TODO: consolidate this with initialization (DRY)
|
|
themeSwitch?.addEventListener("change", () => {
|
|
if (themeSwitch.checked) {
|
|
document.body.classList.add("theme-dark");
|
|
document.body.classList.remove("theme-light");
|
|
localStorage.setItem("theme", "dark");
|
|
}
|
|
else {
|
|
document.body.classList.remove("theme-dark");
|
|
document.body.classList.add("theme-light");
|
|
localStorage.setItem("theme", "light");
|
|
}
|
|
});
|
|
} |