Skip to content

Instantly share code, notes, and snippets.

@natterstefan
Forked from ottsch/add_favicons.js
Created December 8, 2020 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natterstefan/063c9ca16d00c02671732193ed2ac16e to your computer and use it in GitHub Desktop.
Save natterstefan/063c9ca16d00c02671732193ed2ac16e to your computer and use it in GitHub Desktop.
Add favicon to links
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