diff --git a/assets/js/colors.js b/assets/js/colors.js index 5bc721b51..25f2be076 100644 --- a/assets/js/colors.js +++ b/assets/js/colors.js @@ -65,7 +65,9 @@ function updateCssColors() { // update colors on theme change const darkModeMatcher = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)"); -darkModeMatcher?.addEventListener("change", updateCssColors); +if (darkModeMatcher && darkModeMatcher.addEventListener) { + darkModeMatcher.addEventListener("change", updateCssColors); +} // initialize colors updateCssColors(); window.requestAnimationFrame(updateCssColors); diff --git a/assets/js/theme.js b/assets/js/theme.js index 130532d2b..a4f42fc83 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -62,7 +62,9 @@ function updateMetaThemeForBackdrop() { } export function watchThemeChanges() { - darkModeMatcher?.addEventListener("change", updateTheme); + if (darkModeMatcher && darkModeMatcher.addEventListener) { + darkModeMatcher.addEventListener("change", updateTheme); + } updateTheme(); // listen for modal backdrops