topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday March 29, 2024, 9:23 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Google Rankage, a GM script for adding numbers next to google search results  (Read 6357 times)

mitzevo

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 462
  • Control is power
    • View Profile
    • Donate to Member
Google Rankage, a GM script for adding numbers next to google search results, making it easy to see their positions (saves counting ;).

google-rankage.jpg


Code: Javascript [Select]
  1. // ==UserScript==
  2. // @name            Google Rankage BETA
  3. // @author          mitzevo <http://mitzevo.dcmembers.com/>
  4. // @description     Google Rankage, a GM script for adding numbers next to google search results, making it easy to see their positions (saves counting ;)).
  5. // @include         http://google.*/*
  6. // @include         http://www.google.*/*
  7. // ==/UserScript==
  8.  
  9.  
  10. // todo: filter out news and shopping results on first page.. making the first page appear to have 11 or 12 results..
  11. // todo: improve chinese listings beyond the 100.. probably improve/optimize/compact the code at a later stage or sum thin..
  12. // todo: on google.cn some pages are not showing the numbers, have to debug that.
  13. // todo: when logged into google account, results don't show numbers.. debug.
  14.  
  15. (function() {
  16.         var lang; //Display numbers in English or Chinese ('en' or 'zh')?:
  17.          lang = 'en';
  18.          
  19.         var langhash = new Array(); //unicodes for english and chinese numbers
  20.          langhash['en'] = new Array(); langhash['zh'] = new Array();
  21.          langhash['en'][0] = "\u0030"; langhash['zh'][0] = "\uLING";
  22.          langhash['en'][1] = "\u0031"; langhash['zh'][1] = "\u4e00";
  23.          langhash['en'][2] = "\u0032"; langhash['zh'][2] = "\u4e8c";
  24.          langhash['en'][3] = "\u0033"; langhash['zh'][3] = "\u4e09";
  25.          langhash['en'][4] = "\u0034"; langhash['zh'][4] = "\u56db";
  26.          langhash['en'][5] = "\u0035"; langhash['zh'][5] = "\u4e94";
  27.          langhash['en'][6] = "\u0036"; langhash['zh'][6] = "\u516d";
  28.          langhash['en'][7] = "\u0037"; langhash['zh'][7] = "\u4e03";
  29.          langhash['en'][8] = "\u0038"; langhash['zh'][8] = "\u516b";
  30.          langhash['en'][9] = "\u0039"; langhash['zh'][9] = "\u4e5d";
  31.          langhash['en'][10] = "\u0039"; langhash['zh'][10] = "\u5341";
  32.          //langhash['en'][11] = "\u0031\u0030"; langhash['zh'][11] = "\u5341\u4e00"; //.. we will generate the sequence later instead of hardcoding.
  33.        
  34.         var start = window.location.href.match("start=([0-9]+)"); //get the start param value from the loaded/loading/gs'd page..
  35.          start = (start == null)? 0 : start[1]; //alert("start = "+start); // ^if it doesn't exist, it's a fresh page/first page listing.
  36.         var page = start/10 + 1; //page = (pos == 0)? 1 : (pos/10 + 1); alert("page = "+page);
  37.         var pos = start; //pos = start;
  38.  
  39.         //find out which <ol> contains the organic results by matching the footprint.. (easily found when comparing the html source of a few G queries)
  40.         var ol = document.getElementsByTagName("ol")[0]; // let's try the first one..
  41.          ol = (ol.innerHTML.substr(0,8) == '<!--m-->') ? ol : document.getElementsByTagName("ol")[1]; //does the first match the footprint? if not, it's the second one we're after
  42.          ol = (ol.innerHTML.substr(0,8) == '<!--m-->') ? ol : document.getElementsByTagName("ol")[2]; //does the second match the footprint? if not, it's the thirc one we're after
  43.          ol = (ol.innerHTML.substr(0,8) == '<!--m-->') ? ol : document.getElementsByTagName("ol")[3]; //does the third match the footprint? if not, it's the fourth one we're after
  44.         var lis = ol.getElementsByTagName('li');                 
  45.         for(var i = 0, li; li = lis[i]; i++){
  46.                 if(li.className=='g'){
  47.                         var ones, tens, position;
  48.                         pos++;
  49.                         if(pos < 10){
  50.                                 position = langhash[lang][pos];
  51.                         }else if(pos < 100){
  52.                                 position = String(pos);
  53.                                 tens = langhash[lang][position.substr(0,1)]; ones = langhash[lang][position.substr(1,1)];
  54.                                 if(lang == 'en'){
  55.                                         position = tens+ones
  56.                                 }else{
  57.                                         if(pos > 9 && pos < 20)
  58.                                          position = (pos != 10)? langhash['zh'][10]+ones : langhash['zh'][10];
  59.                                         else if(pos > 19 && pos < 100)
  60.                                          position = (pos != 20 && pos != 30 && pos != 40 && pos != 50 && pos != 60 && pos != 70 && pos != 80 && pos != 90)? tens+langhash['zh'][10]+ones : tens+langhash['zh'][10];
  61.                                         else
  62.                                          position = tens+langhash['zh'][10]+ones;
  63.                                 }
  64.                         }
  65.                         li.innerHTML = '<span style="color: black; background-color: yellow; font-family: tahoma; font-size: 11px; font-weight: bold; border: none; padding: 1px 3px 2px 3px;"><a title=\''+position+'\'>'+position+'</a></span> '+li.innerHTML;
  66.                 }
  67.         }
  68. })();

I know there are lot of search/seo tools (browser extensions, softwares, scripts, etc.) that already include the feature of adding numbers next to search listing, but I just wanted to make a small script just for my use - I thought I'd share it, and there it is in beta form :) It's not much, but it does have an option to specify to display ENGLISH or CHINESE numbers which I think is pretty cool considering I've never coded any thing with any type of language support :P and because it gave me a small task to achieve.

You can add this to GM by saving this code as a new file, probably google_rankage.user.js (must have the .user.js ending), and dropping the file into Firefox (assusming GM is indeed installed and enabled!)
The clock is running. Make the most of today. Time waits for no man. Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it is called the present.
« Last Edit: March 05, 2009, 06:10 PM by mitzevo »

mitzevo

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 462
  • Control is power
    • View Profile
    • Donate to Member
Just a side note, when I set out for the task of getting numbers next to the google search results, in the html, the results are actually inside an OL, which is suppose to order LI's by default.. but the google css overrides it with list-style-type: none, and list-style-position: outside, if you change these to values to some thing appropriate (such as
list-style-type: numerals and list-style-position: inside) the numbers will then show up :) So you could just set a class on the OL and set the LI styles to make the numbers appear (as they should).. etc. I decided to do it a diff/longer way ^.
The clock is running. Make the most of today. Time waits for no man. Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it is called the present.
« Last Edit: March 05, 2009, 01:36 PM by mitzevo »

mitzevo

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 462
  • Control is power
    • View Profile
    • Donate to Member
The clock is running. Make the most of today. Time waits for no man. Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it is called the present.