// HighlightAussies
// version 0.2
// 2005-05-22
// Copyright (c) 2005, Michael Strasser
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "HighlightAussies", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          HighlightAussies
// @namespace     http://relativelyignorant.net
// @description   Highlight result lines that refer to Australians in cyclingnews.com pages
// @include       http://*.cyclingnews.com/*
// ==/UserScript==
//
// --------------------------------------------------------------------
//
(function() {

	// Specify the country abbreviation and highlight colour.
	var COUNTRY = "Aus";
	var HL_COLOUR = "#88FF88";

	var prenodes, regex, i, node, html;
	
	// Result lines are all in <pre> nodes.
	prenodes = document.evaluate(
		"//pre",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null
	);

	// Search for whole lines that contain the string "(Aus)".
	// They exclude the surrounding newline characters.
	// On Windows the lines are surrounded by \r\n sequences, so exclude both.
	regex = new RegExp("[^\\n]+\\(" + COUNTRY + "\\)[^\\r\\n]+", "ig");

	for (i = 0; i < prenodes.snapshotLength; ++i) {
		node = prenodes.snapshotItem(i);
		html = node.innerHTML;
		// Replace the searched-for line with a highlighted version of it.
		html = html.replace(
			regex,
			"<span style='background-color: " + HL_COLOUR + "'>$&</span>"
		);
		node.innerHTML = html;
	}

})();


