Last active
July 16, 2022 17:56
-
-
Save ottsch/51a3640910a82d36fcd1fc70ad4b109b to your computer and use it in GitHub Desktop.
Add favicon to links in Roam Research
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
new MutationObserver(() => { | |
let filtered = Array.prototype.filter.call( | |
document.querySelectorAll(".roam-body a"), | |
(a) => { | |
return a.hostname && !a.hostname.includes("roamresearch.com"); | |
} | |
); | |
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"; | |
} | |
}); | |
}).observe(document.body, { | |
attributes: true, | |
childList: true, | |
subtree: true, | |
}); |
kmaustral
commented
Jan 20, 2021
via email
Thanks Abhay. Is there something that can be added to other scripts that
are broken? Would `load<script name>();` do it?
…On Thu, 21 Jan 2021 at 01:08, Abhay Prasanna ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Adding an async function wrapper seems to fix all broken JS. HT: @GitMurf
<https://github.com/GitMurf> for the heads-up.
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
});
}
loadFavicons();
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/51a3640910a82d36fcd1fc70ad4b109b#gistcomment-3600685>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARTR6N2MBUG6PZGAKAHRJZDS23PV3ANCNFSM4Q77UX5A>
.
Really weird, still NOK for me... Same issue with Roamhacker_daytitle script... Could it be related to a combination of different scripts?
@ottsch any interest in updating this for the new official Roam plugin marketplace? If not would you be comfortable passing the reins to me or someone in the Roam community to keep it updated?
@8bitgentleman of course, go ahead!
Full disclosure @ottsch there is the potential for some proceeds from Roam for those who update and maintain plugins on the marketplace. Want to make sure you're aware of that and still OK with passing it on
@8bitgentleman Yep, that's fine with me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment