From 7b2b1f6b837dbca3dd08cb89836cb1ae098c2bd8 Mon Sep 17 00:00:00 2001 From: Christian Hodgden Date: Tue, 3 Feb 2026 16:25:44 -0600 Subject: Initial Commit. Yay --- static/css/dark-mode.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 static/css/dark-mode.js (limited to 'static/css/dark-mode.js') 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'); -- cgit v1.2.3