Welcome Guest.   Make a donation to an author on the site February 09, 2010, 10:14:23 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Latest Newsletter: February 9th, 2010 - "Valentine Computing"
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Google Rankage, a GM script for adding numbers next to google search results  (Read 1166 times)
mitzevo
Supporting Member
**
Posts: 365


evil... I've come to tell you that she's evil..

View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« on: March 05, 2009, 01:20:40 PM »

Google Rankage, a GM script for adding numbers next to google search results, making it easy to see their positions (saves counting Wink.




Formatted for Javascript with the GeSHI Syntax Highlighter v1.0.8.4 [copy or print]
  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 smiley 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 tongue 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!)
« Last Edit: March 05, 2009, 06:10:08 PM by mitzevo » Logged
mitzevo
Supporting Member
**
Posts: 365


evil... I've come to tell you that she's evil..

View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: March 05, 2009, 01:32:20 PM »

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 smiley 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 ^.
« Last Edit: March 05, 2009, 01:36:10 PM by mitzevo » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
SMF © 2006-2009, Simple Machines LLC

social bookmark this page