Created
August 31, 2021 06:19
-
-
Save chadluo/90b97375edb3e1abccfedf0fab21c402 to your computer and use it in GitHub Desktop.
Google search get favicon and hide http/https
This file contains 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 Google search favicon | |
// @namespace http://tampermonkey.net/ | |
// @author chadluo | |
// @match https://www.google.com/search* | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
(function() { | |
setTimeout(annotate, 1500); | |
})(); | |
function annotate() { | |
document.querySelectorAll('.g cite').forEach((cite) => { | |
const urlElement = cite.childNodes[0]; | |
const url = new URL(urlElement.textContent); | |
urlElement.textContent = urlElement.textContent.replaceAll(/(http|https):\/\//g, ''); | |
const icon = document.createElement('img'); | |
icon.src = "https://www.google.com/s2/favicons?sz=32&domain=" + url.hostname; | |
icon.style = 'position:absolute;top:50%;transform:translateY(-50%);width:16px;height:16px;'; | |
cite.style = 'padding-left:22px;'; | |
cite.before(icon); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment