Created
December 15, 2020 13:36
-
-
Save houshuang/15a3a29530be8501ee6e994d2cc2c811 to your computer and use it in GitHub Desktop.
Favicons in Roam
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
const addFavicons = () => { | |
let filtered = Array.prototype.filter.call(document.querySelectorAll('.roam-body a'), a => { | |
return a.hostname && a.hostname !== document.location.hostname; | |
}); | |
Array.prototype.forEach.call(filtered, a => { | |
if (a.text == "*") { | |
a.style.background = `url(https://www.google.com/s2/favicons?sz=16&domain=${a.hostname}) right center no-repeat`; | |
a.style.paddingRight = "18px"; | |
} else { | |
a.style.background = `url(https://www.google.com/s2/favicons?sz=16&domain=${a.hostname}) left center no-repeat`; | |
a.style.paddingLeft = "20px"; | |
} | |
}); | |
}; | |
const observer = new MutationObserver(addFavicons); | |
observer.observe(document.querySelector('.roam-body'), { | |
attributes: true, | |
childList: true, | |
subtree: true | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment