Source for "Linkify Google green URLs"

By Jacob Bower
Has no other scripts.


/*
	Greasemonkey script to linkify google green URLs
	Copyright (C) Jacob Bower <jacob.bowerATalumni.doc.ic.ac.uk>

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	Details of the GNU General Public License can be found at:
	http://www.gnu.org/
*/

// ==UserScript==
// @name          Linkify Google green URLs
// @namespace     http://www.doc.ic.ac.uk/~jab00/ 
// @description   For each google search hit, changes the usually non-clickable green URL into a series of clickable links for each '/' delimited part.
// @include       http://www.google.*/search*
// ==/UserScript==

function makeAnchor(url, text)
{
	return "<a href='" + url + "' color='#008000'>" + text + "</a>";
}

function makeLink(site, dirs)
{

	var href = "http://" + site;
	var link_str = makeAnchor(href, site);

	for(var i = 0; i < dirs.length; i++) {
		if(i != 0) {
			href += "/";
			link_str += "/";
		}
		href += dirs[i];
		if(i == dirs.length - 1)
			link_str += makeAnchor(href, dirs[i]);
		else
			link_str += makeAnchor(href + "/", dirs[i]);
	}

	return link_str;
}

var allElements, thisElement;
allElements = document.getElementsByTagName('font');
for (var i = 0; i < allElements.length; i++) {
	thisElement = allElements[i];
	if(thisElement.color.match(/#008000/)) {
		var parts = thisElement.textContent.match(/([^/]*)([^ ]*)(.*)/);
		sub_dirs = parts[2].split("/");
		thisElement.textContent = "";
		thisElement.innerHTML = makeLink(parts[1], sub_dirs) + parts[3];
	}
}