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>
|
||||
(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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user