summaryrefslogtreecommitdiff
path: root/static/js/theme-switch.js
diff options
context:
space:
mode:
authorFrancesco Tomaselli <tomaselli.fr@gmail.com>2025-02-21 09:48:40 +0100
committerGitHub <noreply@github.com>2025-02-21 09:48:40 +0100
commit4ed992287f8a3e26fd8b198816e89253d97b4cdd (patch)
treef6ad65b43a2f2c39325b212b308ce1fa7188fc66 /static/js/theme-switch.js
parent497f3d51c30de5a449846fca9c989044f37a0df5 (diff)
parent2310f6160404914c7245c3178bc8f0f0532b2caf (diff)
Merge pull request #86 from OleMussmann/configure-mermaid-theme
Configure mermaid theme
Diffstat (limited to 'static/js/theme-switch.js')
-rw-r--r--static/js/theme-switch.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/static/js/theme-switch.js b/static/js/theme-switch.js
new file mode 100644
index 0000000..a617fda
--- /dev/null
+++ b/static/js/theme-switch.js
@@ -0,0 +1,28 @@
+function isAuto() {
+ return document.body.classList.contains("auto");
+}
+
+function setTheme() {
+ if (!isAuto()) {
+ return
+ }
+
+ document.body.classList.remove("auto");
+ let cls = "light";
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ cls = "dark";
+ }
+
+ document.body.classList.add(cls);
+}
+
+function invertBody() {
+ document.body.classList.toggle("dark");
+ document.body.classList.toggle("light");
+}
+
+if (isAuto()) {
+ window.matchMedia('(prefers-color-scheme: dark)').addListener(invertBody);
+}
+
+setTheme();