Last active
July 12, 2023 13:12
-
-
Save overflowy/bf5d9aedffcd46242a253a3ddf1271b4 to your computer and use it in GitHub Desktop.
Favicons for HN
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
// ==UserScript== | |
// @name Favicons for HN | |
// @namespace Violentmonkey Scripts | |
// @match https://*.ycombinator.com/* | |
// @grant none | |
// @version 1.0 | |
// @author [email protected] | |
// @description 12/19/2022, 9:34:53 AM | |
// @inject-into content | |
// ==/UserScript== | |
var favicons = document.getElementsByClassName("favicon"); | |
if (!(favicons.length > 0)) { | |
const articleLinks = document.querySelectorAll(".titleline > a"); | |
for (let link of articleLinks) { | |
const domain = new URL(link.href).hostname; | |
const imageUrl = `https://icons.duckduckgo.com/ip3/${domain}.ico`; | |
const imgEl = document.createElement("img"); | |
imgEl.src = imageUrl; | |
imgEl.className = "favicon"; | |
imgEl.width = 14; | |
imgEl.height = 14; | |
imgEl.style.paddingRight = "0.25em"; | |
imgEl.style.paddingLeft = "0.25em"; | |
link.style.alignItems = "center"; | |
link.style.display = "inline-flex"; | |
link.style.justifyContent = "center"; | |
link.prepend(imgEl); | |
} | |
} |
Author
overflowy
commented
Jun 6, 2023
here's an alternative that uses the google API to fetch the favicons. Don't know why but on my devices, all the favicons coming from the duckduckgo API render out to a grey circled arrow.
Thank you for this cool user-script though !
// ==UserScript==
// @name Favicons for HN
// @namespace Violentmonkey Scripts
// @match https://*.ycombinator.com/*
// @grant none
// @version 1.0
// @author [email protected]
// @description 07/06/2023, 08:48:00 AM
// @inject-into content
// ==/UserScript==
var favicons = document.getElementsByClassName("favicon");
if (!(favicons.length > 0)) {
const articleLinks = document.querySelectorAll(".titleline > a");
for (let link of articleLinks) {
const domain = new URL(link.href).hostname;
const imageUrl = `https://s2.googleusercontent.com/s2/favicons?domain=${domain}&sz=32`;
const imgEl = document.createElement("img");
imgEl.src = imageUrl;
imgEl.className = "favicon";
imgEl.width = 14;
imgEl.height = 14;
imgEl.style.paddingRight = "0.25em";
imgEl.style.paddingLeft = "0.25em";
link.style.alignItems = "center";
link.style.display = "inline-flex";
link.style.justifyContent = "center";
link.prepend(imgEl);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment