Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Hide multiple results from one domain
- // @description Hides multiple results from the same domain in google
- // @version 0.1
- // @author Dale Swanson
- // @namespace http://daleswanson.org/
- // @homepage http://userscripts.org/scripts/show/11213
- // @icon http://www.google.com/favicon.ico
- // @include *.google.*/search*
- // ==/UserScript==
- //(function main(){
- (function(){
- var thisurl, thisresult, urls;
- var ismultiple = 0;
- //this is the class google uses for each result
- //each result is a <li> with class 'g':
- //<li class="g">
- var results = document.getElementsByClassName('g');
- var prevurl="www.google.com";
- for (i = 0; i < results.length; i++)
- {//each result is stored in results
- ismultiple=0;
- thisresult = results[i].innerHTML; //grab contents so that we can find url
- GM_log("Result #" + i + " = " + thisresult);
- urls = results[i].getElementsByTagName('a'); //grab urls, first one should be result
- thisurl = urls[0].toString();
- GM_log("URL #" + i + " = " + thisurl);
- //thisurl should contain the full url for this result now
- thisurl = thisurl.replace(/^.*tp.*:\/\//,''); //strip out http:// and similar
- thisurl = thisurl.replace(/\/.*/,''); //strip out stuff after domain
- //thisurl should contain just the domain now
- GM_log("Domain #" + i + " = " + thisurl);
- //there are a lot of ways to go from here:
- //1. we could just see if domain matches previous and then hide result (easy)
- //2. we could count domain, and see if it is > some set cut off (more options)
- //2.1 if we do that we should decide if count should be reset when a differnt domain is found
- //3. we could process domain and allow a varied level of url to count eg:
- //en.wikipedia.org vs de.wikipedia.org
- //4. the alternative to that would be just to strip www from the front, maybe some other common ones
- if (thisurl == prevurl)
- {//it's a multiple
- ismultiple = 1; //it is a multiple
- GM_log("Hide #" + i + " prev: " + prevurl + " this: " + thisurl);
- }
- prevurl = thisurl;
- //hide this result
- if (ismultiple) results[i].style.display = 'none';
- }
- urls = null;
- results = null;
- GM_log("End " + urls + results);
- })();
- //})
- //main();
Advertisement
Add Comment
Please, Sign In to add comment