Last active
October 28, 2020 01:12
-
-
Save elkhayder/b158efd4de7a89eac79c4ab2776a9171 to your computer and use it in GitHub Desktop.
Auto detect browser theme for custom favicons
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
const icon = document.createElement('link'); | |
icon.setAttribute('rel', 'icon'); | |
icon.setAttribute('type', 'image/png'); | |
iconLink = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? "favicon-white.png" : "favicon-black.png"; | |
icon.setAttribute('href', iconLink); | |
document.head.appendChild(icon); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment