if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { // dark mode } window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => { const newColorScheme = e.matches ? "dark" : "light"; })