diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/setTheme.ts | 8 | ||||
-rw-r--r-- | js/toggleTheme.ts | 18 |
2 files changed, 26 insertions, 0 deletions
diff --git a/js/setTheme.ts b/js/setTheme.ts new file mode 100644 index 0000000..d9a6cf8 --- /dev/null +++ b/js/setTheme.ts @@ -0,0 +1,8 @@ +function setTheme(theme: string) { + console.log("setting theme to `" + theme + "`"); + + let body = document.getElementById("body")!; + body.setAttribute("data-theme", theme); + + localStorage.setItem("theme", theme); +} diff --git a/js/toggleTheme.ts b/js/toggleTheme.ts new file mode 100644 index 0000000..fd15dae --- /dev/null +++ b/js/toggleTheme.ts @@ -0,0 +1,18 @@ +/// <reference path="setTheme.ts" /> + +function toggleTheme() { + let theme = localStorage.getItem("theme"); + + if (theme == "light") { + theme = "dark"; + } else if (theme == "dark") { + theme = "light"; + } else { + console.log!("invalid theme `" + theme + "`"); + + // Use default: + theme = "dark"; + } + + setTheme(theme); +} |