Follow system color scheme live
The dark-mode script set the .dark class once at load. Subscribe to the prefers-color-scheme media query so the theme also updates while the page is open when the OS appearance changes. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -14,9 +14,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
if (!window.matchMedia) return;
|
||||||
document.documentElement.classList.add("dark");
|
var mq = window.matchMedia("(prefers-color-scheme: dark)");
|
||||||
}
|
var apply = function () { document.documentElement.classList.toggle("dark", mq.matches); };
|
||||||
|
apply();
|
||||||
|
mq.addEventListener("change", apply);
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user