Skip to content

Instantly share code, notes, and snippets.

@sachahjkl
Created October 9, 2023 12:14
Show Gist options
  • Save sachahjkl/3b0fc50a03805e4ed2c660830f862d84 to your computer and use it in GitHub Desktop.
Save sachahjkl/3b0fc50a03805e4ed2c660830f862d84 to your computer and use it in GitHub Desktop.
Favicons for HN Google
// ==UserScript==
// @name Favicons for HN Google
// @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 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