HackerNews FavIcons

Shows favicon for every link in hackernews

بۇ قوليازمىنى قاچىلاش؟
ئاپتورنىڭ تەۋسىيەلىگەن قوليازمىسى

سىز بەلكىم HackerNews Links recap with Comment Anchors نى ياقتۇرۇشىڭىز مۇمكىن.

بۇ قوليازمىنى قاچىلاش

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         HackerNews FavIcons
// @namespace    PoKeRGT
// @version      1.00
// @icon         https://www.google.com/s2/favicons?sz=64&domain=news.ycombinator.com
// @description  Shows favicon for every link in hackernews
// @author       PoKeRGT
// @match        https://news.ycombinator.com/*
// @grant        GM_addElement
// @run-at       document-end
// @homepageURL  https://github.com/PoKeRGT/userscripts
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  for (let item of document.querySelectorAll('.titleline')) {
    item.style.display = "flex";
    item.style.alignItems = "center";
    const link = item.querySelector('a');
    const domain = new URL(link.href).hostname;
    const imageUrl = `https://www.google.com/s2/favicons?sz=16&domain_url=${domain}`;

    const container = document.createElement('span');
    container.style.paddingRight = '0.25em';
    container.style.paddingLeft = '0.25em';
    item.prepend(container);

    const newTabLink = document.createElement('a')
    newTabLink.href = link.href
    newTabLink.target = '_blank'

    container.appendChild(newTabLink)

    GM_addElement(newTabLink, 'img', {
      src: imageUrl,
      width: 16,
      height: 16
    });
  }
})();