summaryrefslogtreecommitdiff
path: root/static/js/util
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2025-01-03 01:47:07 -0800
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2025-01-03 01:47:07 -0800
commitf163a242792cd325c9414587d52f3d8584f28df1 (patch)
treeb57ad121cc3f4ffc2bc55f4d63bfaaf6026dd239 /static/js/util
downloadphoneof-f163a242792cd325c9414587d52f3d8584f28df1.tar.gz
phoneof-f163a242792cd325c9414587d52f3d8584f28df1.zip
initial commit
Diffstat (limited to 'static/js/util')
-rw-r--r--static/js/util/setThemeBeforeRender.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/static/js/util/setThemeBeforeRender.js b/static/js/util/setThemeBeforeRender.js
new file mode 100644
index 0000000..b025cce
--- /dev/null
+++ b/static/js/util/setThemeBeforeRender.js
@@ -0,0 +1,11 @@
+const preferredMode = window.matchMedia("(prefers-color-scheme: dark)").matches
+ ? "DARK"
+ : "LIGHT";
+
+// sets theme before rendering & jquery loaded to prevent flashing of uninitialized theme
+// (ugly white background)
+localStorage.setItem("theme", localStorage.getItem("theme") || preferredMode);
+document.documentElement.setAttribute(
+ "data-theme",
+ localStorage.getItem("theme"),
+);