Last active
March 31, 2020 19:43
-
-
Save jodyheavener/e2234d8d9c269c613944bb177e3bf9fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function setFavicon(scheme) { | |
| const svgFavicon = document.querySelector('.js-site-favicon[type="image/svg+xml"]'), | |
| pngFavicon = document.querySelector('.js-site-favicon[type="image/png"]'); | |
| scheme || (scheme = "light"); | |
| if (svgFavicon && pngFavicon) { | |
| svgFavicon.href = `favicon-${scheme}.svg`; | |
| pngFavicon.href = `favicon-${scheme}.png`; | |
| } | |
| } | |
| function prefersDark() { | |
| return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; | |
| } | |
| prefersDark() && setFavicon("dark"); | |
| window.matchMedia("(prefers-color-scheme: dark)").addListener(() => { | |
| setFavicon(prefersDark() ? "dark" : "light"); | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment