// ==UserScript==
// @name          Number Google Results
// @namespace     http://www.birnamdesigns.com/userscripts
// @description	  Numbers the results list on Google searches
// @include       http://google.com/*
// @include       http://www.google.com/*
// ==/UserScript==
// Notes:
//   * is a wildcard character
//   .tld is magic that matches all top-level domains (e.g. .com, .co.uk, .us, etc.)

var n = 1;

// find the page offset by looking at the query string
var querystring = document.location.search;
querystring = querystring.substr(1);
querypairs = querystring.split("&");
for (var q=0; q<querypairs.length; q++) {
	if (querypairs[q].indexOf("start=") != -1) {
		querystart = querypairs[q].split("=");
		n = (querystart[1]/1) + 1;
	}
}

// google now uses divs!
var d_tags = document.getElementsByTagName("div");
for (var i=0; i<d_tags.length; i++) {
	var d = d_tags[i];
	if (d.className == "g") {
		var par = d.parentNode;
		var fchild = d.childNodes[0];
		var newnode = document.createElement("span");
		var textnode = document.createTextNode(n);
		newnode.appendChild(textnode);
		newnode.style.fontSize = "9px";
		newnode.style.color = "#F00";
		newnode.style.border = "solid 1px #666";
		newnode.style.backgroundColor = "#FFFEF8";
		newnode.style.padding = "1px 4px";
		newnode.style.marginRight = "4px";
		n++;
		d.insertBefore(newnode, fchild);
	}
}