Last active
July 25, 2022 07:04
-
-
Save bryceadams/503a5cac996cce1187086c01d3fb7aec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)') { | |
var windowPrefersDark = window.matchMedia('(prefers-color-scheme: dark)'); | |
var systemColorMode = windowPrefersDark.matches ? 'dark' : 'light'; | |
// need to check in case doesn't exist like with Safari 13.x | |
if ( | |
'addEventListener' in windowPrefersDark && | |
typeof windowPrefersDark.addEventListener === 'function' | |
) { | |
windowPrefersDark.addEventListener('change', (event) => { | |
systemColorMode = event.matches ? 'dark' : 'light'; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment