// ==UserScript==
// @name        Metro Mojo Hotbox
// @namespace   http://dse.webonastick.com/
// @author      Darren Stuart Embry http://dse.webonastick.com/
// @description If you have mail, display a fixed link in the upper-right corner.
// @include http://www.*mojo.com/*
// @exclude http://www.*mojo.com/*/mymessages.cfm
// @exclude http://www.*mojo.com/*/mymessages.cfm?*
// @exclude http://www.*mojo.com/*/sendmessage.cfm
// @exclude http://www.*mojo.com/*/sendmessage.cfm?*
// ==/UserScript==
//
// This is a Greasemonkey user script.
// To install it, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox, and revisit this script.
//
// If you're still using Internet Explorer, then well, it ain't my problem.

(function() {

	var anchors = document.getElementsByTagName("a");
	if (!anchors || !anchors.length) return;

	for (var i = 0; i < anchors.length; ++i) {
		var anchor = anchors[i];
		var href = anchor.href;
		if (!href) continue;

		if (!(/mymessages\.cfm/i.test(href))) continue;

		if (!anchor.hasChildNodes()) continue;
		var text = anchor.innerHTML;

// 		var child = anchor.childNodes[0];
// 		if (child.nodeType != 3) continue; /* 3 == Node.TEXT_NODE */
// 		var text = child.data;

		var regexps = [
				/\b(\d+) msgs?\b/i, 
				/\bhot ?box (\d+)\b/,
				/\bhot ?box <span.*?>(\d+)<\/span>/,
		];

		for (var j = 0; j < regexps.length; ++j) {
			var match = text.match(regexps[j]);
			if (match && match.length) {
				var msgs = match[1];
				var newAnchor = document.createElement("a");
				newAnchor.href = anchor.href;
				newAnchor.appendChild(document.createTextNode(
					"hot box " + msgs));
				newAnchor.style.position = "fixed";
				newAnchor.style.top = "0px";
				newAnchor.style.right = "0px";
				newAnchor.style.padding = "4px";
				newAnchor.style.textDecoration = "none";
				newAnchor.style.backgroundColor = "red";
				newAnchor.style.color = "yellow";
				newAnchor.style.fontWeight = "bold";
				newAnchor.style.fontFamily =
					"arial, helvetica, sans-serif";
				newAnchor.style.fontSize = "x-large";
				newAnchor.style.borderStyle = "solid";
				newAnchor.style.borderColor = "yellow";
				newAnchor.style.borderWidth = "2px";
				document.body.appendChild(newAnchor);
				return;
			}
		}
	}
})();
