daleswanson

Untitled

Aug 16th, 2012
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Hide multiple results from one domain
  3. // @description     Hides multiple results from the same domain in google
  4. // @version     0.1
  5. // @author      Dale Swanson
  6. // @namespace       http://daleswanson.org/
  7. // @homepage        http://userscripts.org/scripts/show/11213
  8. // @icon        http://www.google.com/favicon.ico
  9. // @include     *.google.*/search*
  10. // ==/UserScript==
  11.  
  12. //(function main(){
  13. (function(){
  14.    
  15.     var thisurl, thisresult, urls;
  16.     var ismultiple = 0;
  17.     //this is the class google uses for each result
  18.     //each result is a <li> with class 'g':
  19.     //<li class="g">
  20.     var results = document.getElementsByClassName('g');
  21.     var prevurl="www.google.com";
  22.    
  23.     for (i = 0; i < results.length; i++)
  24.     {//each result is stored in results
  25.         ismultiple=0;
  26.         thisresult = results[i].innerHTML; //grab contents so that we can find url
  27.         GM_log("Result #" + i + " = " + thisresult);
  28.        
  29.         urls = results[i].getElementsByTagName('a'); //grab urls, first one should be result
  30.         thisurl = urls[0].toString();
  31.         GM_log("URL #" + i + " = " + thisurl);
  32.         //thisurl should contain the full url for this result now
  33.        
  34.         thisurl = thisurl.replace(/^.*tp.*:\/\//,''); //strip out http:// and similar
  35.         thisurl = thisurl.replace(/\/.*/,''); //strip out stuff after domain
  36.         //thisurl should contain just the domain now   
  37.         GM_log("Domain #" + i + " = " + thisurl);
  38.        
  39.         //there are a lot of ways to go from here:
  40.         //1. we could just see if domain matches previous and then hide result (easy)
  41.         //2. we could count domain, and see if it is > some set cut off (more options)
  42.         //2.1 if we do that we should decide if count should be reset when a differnt domain is found
  43.        
  44.         //3. we could process domain and allow a varied level of url to count eg:
  45.         //en.wikipedia.org vs de.wikipedia.org
  46.         //4. the alternative to that would be just to strip www from the front, maybe some other common ones
  47.        
  48.         if (thisurl == prevurl)
  49.         {//it's a multiple
  50.             ismultiple = 1; //it is a multiple
  51.             GM_log("Hide #" + i + " prev: " + prevurl + " this: " + thisurl);
  52.         }
  53.        
  54.         prevurl = thisurl;
  55.            
  56.         //hide this result
  57.         if (ismultiple) results[i].style.display = 'none';
  58.     }
  59.    
  60. urls = null;
  61. results = null;
  62.  
  63. GM_log("End " + urls + results);   
  64.    
  65. })();
  66.  
  67. //})
  68. //main();
Advertisement
Add Comment
Please, Sign In to add comment