window.matchMedia check

This commit is contained in:
gurusabarish
2023-01-21 23:34:17 +05:30
parent 1d476eb2b5
commit c28b579ab6
4 changed files with 7 additions and 21 deletions
+2 -2
View File
@@ -6,7 +6,7 @@
document.body.classList.add('dark');
} else if (localStorage.getItem("pref-theme") === "light") {
document.body.classList.remove('dark')
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
}
@@ -14,7 +14,7 @@
{{- /* theme-toggle is disabled and theme is auto */}}
{{- else if (and (ne .Site.Params.theme.defaultTheme "light") (ne .Site.Params.theme.defaultTheme "dark"))}}
<script>
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
}