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:
Émile Ré
2026-06-28 15:01:11 +02:00
parent c004490b07
commit 148f753528

View File

@@ -14,9 +14,11 @@
<script>
(function () {
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
document.documentElement.classList.add("dark");
}
if (!window.matchMedia) return;
var mq = window.matchMedia("(prefers-color-scheme: dark)");
var apply = function () { document.documentElement.classList.toggle("dark", mq.matches); };
apply();
mq.addEventListener("change", apply);
})();
</script>