Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rhnvrm/bodhi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/main.js')
-rw-r--r--static/js/main.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/static/js/main.js b/static/js/main.js
index 5504784..63ee4a4 100644
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -1,4 +1,21 @@
let element = document.getElementById("main");
if (document.body.clientWidth < 632) {
element.scrollIntoView({behavior: "smooth"});
-} \ No newline at end of file
+}
+
+
+// Set the theme
+// Ref: https://livecodestream.dev/post/2020-08-06-a-better-approach-to-dark-mode-on-your-website/
+// Capture the current theme from local storage and adjust the page to use the current theme.
+const htmlEl = document.getElementsByTagName('html')[0];
+const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
+
+if (currentTheme) {
+ htmlEl.dataset.theme = currentTheme;
+}
+
+// When the user changes the theme, we need to save the new value on local storage
+const toggleTheme = (theme) => {
+ htmlEl.dataset.theme = theme;
+ localStorage.setItem('theme', theme);
+}