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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative - https://hackernews.betacat.io/
with: