aboutsummaryrefslogtreecommitdiff
path: root/dst/scripts
diff options
context:
space:
mode:
authoradam <56338480+adastx@users.noreply.github.com>2022-08-28 10:16:39 +0200
committeradam <56338480+adastx@users.noreply.github.com>2022-08-28 10:20:56 +0200
commitc7ba27acc50b06f0f7c2cced9b609a15cc9552d9 (patch)
treef4f7625186f5841ddec667989660a51c0897ce06 /dst/scripts
parent77cfc954e906edbf9a72aae5fa5fa091e58b014a (diff)
Added option to toggle dark mode
Diffstat (limited to 'dst/scripts')
-rw-r--r--dst/scripts/darktheme.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/dst/scripts/darktheme.js b/dst/scripts/darktheme.js
new file mode 100644
index 0000000..a06aca2
--- /dev/null
+++ b/dst/scripts/darktheme.js
@@ -0,0 +1,27 @@
+// Get the theme toggle input
+const currentTheme = localStorage.getItem("theme"); // If the current local storage item can be found
+
+if (window.matchMedia
+ && window.matchMedia("(prefers-color-scheme: dark)").matches
+ && !localStorage.getItem("theme")) {
+ localStorage.setItem("theme", "dark");
+}
+
+// Function that will switch the theme based on the if the theme toggle is checked or not
+function switchTheme() {
+ if (document.body.classList.contains('dark-mode')) {
+ document.body.classList.remove("dark-mode");
+ localStorage.setItem("theme", "light");
+ } else {
+ document.body.classList.add("dark-mode");
+ localStorage.setItem("theme", "dark");
+ }
+}
+// Get the current theme from local storage
+if (currentTheme === "dark") {
+ document.body.classList.add("dark-mode");
+ localStorage.setItem("theme", "dark");
+} else {
+ document.body.classList.remove("dark-mode");
+ localStorage.setItem("theme", "light");
+}