mirror of
https://github.com/zadam/trilium.git
synced 2026-03-17 01:20:30 +01:00
27 lines
985 B
TypeScript
27 lines
985 B
TypeScript
|
|
export default function setupThemeSelector() {
|
||
|
|
const themeSwitch: HTMLInputElement = document.querySelector(".theme-selection input")!;
|
||
|
|
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");
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
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");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|