diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2025-01-05 16:39:13 -0800 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2025-01-05 16:39:13 -0800 |
commit | d25ec27fb1c3df175e1b98af1fdc26881d68a1ab (patch) | |
tree | a79c729b92c0d0a52b19b37c3a506b988f1e0b80 /template/static/js/util/setThemeBeforeRender.js | |
download | whois-d25ec27fb1c3df175e1b98af1fdc26881d68a1ab.tar.gz whois-d25ec27fb1c3df175e1b98af1fdc26881d68a1ab.zip |
initial commit by simponic-infra
Diffstat (limited to 'template/static/js/util/setThemeBeforeRender.js')
-rw-r--r-- | template/static/js/util/setThemeBeforeRender.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/template/static/js/util/setThemeBeforeRender.js b/template/static/js/util/setThemeBeforeRender.js new file mode 100644 index 0000000..b025cce --- /dev/null +++ b/template/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"), +); |