Skip to content

Instantly share code, notes, and snippets.

@goldbattle
Created April 20, 2022 16:00
Show Gist options
  • Save goldbattle/695f869e43fe8d0e628061cb96ed0049 to your computer and use it in GitHub Desktop.
Save goldbattle/695f869e43fe8d0e628061cb96ed0049 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name HN Favicons
// @namespace https://campital.xyz/
// @version 0.3.1
// @license MIT
// @description Favicons for Hacker News
// @match https://*.ycombinator.com/*
// @grant GM.addElement
// ==/UserScript==
(function() {
'use strict';
for (let link of document.querySelectorAll('.titlelink')) {
let domain;
try {
domain = new URL(link.href).hostname;
} catch(err) {
continue;
}
const imageUrl = `https://icons.duckduckgo.com/ip3/${domain}.ico`;
const container = document.createElement('span');
container.style.paddingRight = '0.25em';
container.style.paddingLeft = '0.25em';
container.style.verticalAlign = 'middle';
container.style.filter = 'grayscale(1)';
link.prepend(container);
GM.addElement(container, 'img', {
src: imageUrl,
width: 12,
height: 12
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment