diff --git a/' b/' new file mode 100644 index 0000000..be7c77a --- /dev/null +++ b/' @@ -0,0 +1,47 @@ +$(document).ready(function () { + let lightmode = localStorage.getItem("lightmode") + const HTML = $("html") + const AUDIO = $("#flashbang") + + const enable_light_mode = () => { + HTML.attr("data-color-mode", "light") + localStorage.setItem("lightmode", "enabled") + } + + const disable_light_mode = () => { + HTML.attr("data-color-mode", "dark") + localStorage.setItem("lightmode", null) + } + + if (lightmode === "enabled") { + enable_light_mode() + } + + window + .matchMedia("(prefers-color-scheme: dark)") + .addEventListener("change", (event) => { + if (event.matches) { + disable_light_mode() + } else { + enable_light_mode() + } + }) + + if (window.matchMedia) { + if (window.matchMedia("(prefers-color-scheme: light)").matches) { + enable_light_mode() + } else { + disable_light_mode() + } + } + + $("#color-mode-toggle").click(() => { + lightmode = localStorage.getItem("lightmode") + if (lightmode !== "enabled") { + enable_light_mode() + AUDIO[0].play() + } else { + disable_light_mode() + } + }) +}) diff --git a/static/main/js/lightmode.js b/static/main/js/lightmode.js index 9af9c40..09fddc8 100644 --- a/static/main/js/lightmode.js +++ b/static/main/js/lightmode.js @@ -1,17 +1,15 @@ -$(document).ready(function() { +$(document).ready(function () { let lightmode = localStorage.getItem("lightmode") const HTML = $("html") const AUDIO = $("#flashbang") const enable_light_mode = () => { HTML.attr("data-color-mode", "light") - $("meta[name='color-scheme']").attr("content", "light") localStorage.setItem("lightmode", "enabled") } const disable_light_mode = () => { HTML.attr("data-color-mode", "dark") - $("meta[name='color-scheme']").attr("content", "dark") localStorage.setItem("lightmode", null) } @@ -19,6 +17,24 @@ $(document).ready(function() { enable_light_mode() } + window + .matchMedia("(prefers-color-scheme: dark)") + .addEventListener("change", (event) => { + if (event.matches) { + disable_light_mode() + } else { + enable_light_mode() + } + }) + + // if (window.matchMedia) { + // if (window.matchMedia("(prefers-color-scheme: dark)").matches) { + // disable_light_mode() + // } else { + // enable_light_mode() + // } + // } + $("#color-mode-toggle").click(() => { lightmode = localStorage.getItem("lightmode") if (lightmode !== "enabled") { diff --git a/templates/layout.html b/templates/layout.html index 1771319..e380e67 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -3,7 +3,6 @@
-