// ==UserScript==
// @name           Shack : Add LatestChatty Link
// @namespace      http://www.lmnopc.com/greasemonkey/
// @description    Adds a link to Lastest Chatty to the New Comment / Top links at the bottom of the page
// @include http://shacknews.com/*
// @include http://*.shacknews.com/*
// @exclude http://bananas.shacknews.com/*
// @exclude http://*.gmodules.com/*
// ==/UserScript==
(function() {

	// grab start time of script
	var benchmarkTimer = null;
	var scriptStartTime = getTime();

	function tw_log(str) { GM_log(str); }
	function getTime() { benchmarkTimer = new Date(); return benchmarkTimer.getTime(); }

	function getElementByClassName(oElm, strTagName, strClassName)
	{
		var arrElements = oElm.getElementsByTagName(strTagName);
		for(var i=0; i < arrElements.length; i++)
		{
			if (arrElements[i].className.indexOf(strClassName) == 0)
			{
				return arrElements[i];
			}
		}
	}

	// ADD Latest Chatty TO THE LIST AT THE BOTTOM OF THE COMMENTS 

	var items = document.evaluate("//div[contains(@class, 'commentnav')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	for (item = null, i = 0; item = items.snapshotItem(i); i++)
	{
		item.innerHTML += ' | <a href="http://www.shacknews.com/latestchatty.x">Latest Chatty</a>';
	}

	// log execution time
	tw_log(location.href + ' / ' + (getTime() - scriptStartTime) + 'ms');

})();
