summaryrefslogtreecommitdiff
path: root/static/css/dark-mode.js
diff options
context:
space:
mode:
authorChristian Hodgden <chrhodgden@gmail.com>2026-02-03 16:25:44 -0600
committerChristian Hodgden <chrhodgden@gmail.com>2026-02-03 16:25:44 -0600
commit7b2b1f6b837dbca3dd08cb89836cb1ae098c2bd8 (patch)
tree2e9f027245a84e9c1372f88196ebbdfbf58bf920 /static/css/dark-mode.js
Initial Commit.main
Yay
Diffstat (limited to 'static/css/dark-mode.js')
-rw-r--r--static/css/dark-mode.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/static/css/dark-mode.js b/static/css/dark-mode.js
new file mode 100644
index 0000000..b038fe4
--- /dev/null
+++ b/static/css/dark-mode.js
@@ -0,0 +1,25 @@
+const toggleTheme = function() {
+ document.documentElement.style.setProperty(this.id, Number(this.checked));
+ localStorage.setItem(this.id, Number(this.checked));
+};
+
+const initInput = function(styleVariable=null) {
+ let initValue = localStorage.getItem(styleVariable);
+ if (initValue) {
+ initValue = Number(initValue);
+ document.documentElement.style.setProperty(styleVariable, initValue);
+ } else {
+ initValue = getComputedStyle(document.body).getPropertyValue(styleVariable);
+ initValue = Number(initValue);
+ };
+
+ const inputObject = document.getElementById(styleVariable);
+ if (inputObject) {
+ if (inputObject.type == 'checkbox') {
+ inputObject.addEventListener('change', toggleTheme);
+ inputObject.checked = initValue
+ };
+ };
+};
+
+initInput('--dark-theme-check');