Created
September 3, 2021 01:28
-
-
Save joelmichael/a9720f3e923238a79670fb48450be0af 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
document.addEventListener('DOMContentLoaded', function(event) { | |
var changeColorScheme = function() { | |
var html = document.querySelector('html'); | |
if (this.matches) | |
html.classList.add('dark'); | |
else | |
html.classList.remove('dark'); | |
} | |
var mm = window.matchMedia('(prefers-color-scheme: dark)'); | |
mm.addEventListener('change', changeColorScheme); | |
changeColorScheme.call(mm); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment