Greasy Fork

Greasy Fork is available in English.

Google Favicon

Display Favicons on Google Search

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Google Favicon
// @namespace    http://greasyfork.icu/en/users/943407-webchantment
// @version      1.4
// @description  Display Favicons on Google Search
// @author       Webchantment
// @include      https://www.google.tld/search?*
// @grant        none
// ==/UserScript==

(function() {

	/**SETTINGS**/
	const iconSize = 16; //use 16 or 24

	//check if favicons already exist
	if (document.querySelector("#search > * img[class='XNo5Ab']"))
		return;

	const organic = document.querySelectorAll("#search > * cite");
	const topAds = document.querySelectorAll("#tads > * span[role='text']");
	const bottomAds = document.querySelectorAll("#tadsb > * span[role='text']");

	organic.forEach(o => { prependFavicon(o, o.firstChild.wholeText, false); });
	topAds.forEach(t => { prependFavicon(t, t.getAttribute("data-dtld"), true); });
	bottomAds.forEach(b => { prependFavicon(b, b.getAttribute("data-dtld"), true); });

	function prependFavicon(element, domain, isAd)
	{
		if (domain.includes(".") || isAd)
		{
			const favicon = document.createElement("img");
			favicon.src = `https://www.google.com/s2/favicons?domain=${domain}&sz=${iconSize}`;
			favicon.style = "vertical-align: middle;";

			element.prepend(" ");
			element.prepend(favicon);
		}
	}

})();