// ==UserScript== // @name FaviconizeGoogle // @namespace http://userscripts.org/users/89794 (joeytwiddle) // @description Adds favicons next to Google search results. Also works for startpage.com // @homepage https://greasyfork.org/en/scripts/7664-faviconizegoogle // @downstreamURL http://userscripts.org/scripts/source/48636.user.js // @license ISC // @version 1.4.1 // @include /https?:\/\/((www\.)?|encrypted\.|news\.)google\.[a-z]{2,3}(\.[a-z]{2})?\/(search|webhp|\?gws_rd|\?gfe_rd)?.*/ // @include /https?:\/\/(www\.|[a-z0-9-]*\.)?startpage.com\/.*/ // @grant none // @downloadURL none // ==/UserScript== var placeFaviconByUrl = false; // The little green link below the article title var placeFaviconAfter = false; // Display after the link instead of before it var placeFaviconInsideLink = false; // Makes the favicon clickable but may also get underlined var placeFaviconOffTheLeft = true; // Makes the favicon sit out to the left of the main column (not on startpage) var iconSize = 1.2; // Some alternatives/remixes: // - https://github.com/NV/faviconize-google.js (Chrome extension) // - https://greasyfork.org/en/scripts/12395-google-favicons (works with Endless Google) // - https://gist.github.com/Sir-Cumference/223d36cbec6473b0e6927e5c50c11568 (very short code, @match works with Greasemonkey) // TODO: The relative positioning of the icon appears a bit off for sub-links of the main result. // DONE: Provided more options where to place favicon: by the link or by the // url, before or after, inside or outside the link. However in my opinion // they all suck except the default. ;) // Broken images would be messy, but Firefox seems to hide them after a while // anyway. We do still see the gap from the image's padding though! // It might be desirable to check each image actually exists/loads, or remove it. // Is that possible, without making an http request ourselves? // Third-party host URL detection is implemented leniently, and accordingly // hostname extraction implemented aggressively, which results in favicons // being given to unexpected things like bookmarklets which contain a site url. /* function filterListBy (l,c) { var ret = new Array(); for (var i=0;i a'); } return links; } var style = document.createElement('STYLE'); var padSide = (placeFaviconAfter ? 'left' : 'right'); var extra = placeFaviconOffTheLeft ? 'position: absolute; left: -' + (1 * iconSize + 0.5) + 'em; top: ' + (0.5 + 0.07 - iconSize / 2) + 'em;' : ''; style.innerHTML = ".favicon { padding-" + padSide + ": 4px; vertical-align: middle; width: " + iconSize + "em; height: " + iconSize + "em; padding-bottom: 0.2em; " + extra + "}"; document.getElementsByTagName('head')[0].appendChild(style); function updateFavicons () { var links = getGoogleResultsLinks(); // Allows it to work on any sites: if (links.length === 0) { links = document.getElementsByTagName("A"); } // console.log("Got links = "+links.snapshotLength); // for (var i=0;i is for google, .url is for startpage var targetNode = (placeFaviconByUrl && link.parentNode.parentNode.querySelector('cite, .url') || link); if (placeFaviconInsideLink) { if (placeFaviconAfter) { targetNode.appendChild(img); } else { targetNode.insertBefore(img, targetNode.firstChild); } } else { if (placeFaviconAfter) { targetNode.parentNode.insertBefore(img, targetNode.nextSibling); } else { targetNode.parentNode.insertBefore(img, targetNode); } } } } // TODO: Use MutationObserver instead? var last_srg = null; var results_count = -1; function checkForUpdate () { // #ires was needed for the News tab, which doesn't have a .srg. Perhaps we could use ires for all tabs. var new_srg = document.getElementsByClassName("srg")[0] || document.getElementById("ires") || document.querySelector('.web_regular_results'); //console.log("[FaviconizeGoogle.user.js] last_srg:" ,last_srg); //console.log("[faviconizegoogle.user.js] new_srg:" ,new_srg); var new_results_count = getGoogleResultsLinks().length; if (new_srg !== last_srg || new_results_count !== results_count) { //console.log("Page change detected!"); updateFavicons(); last_srg = new_srg; results_count = new_results_count; } else { //console.log("Pages are the same:", last_srg, new_srg); } setTimeout(checkForUpdate, 1000); } setTimeout(checkForUpdate, 100);