// --------------------------------------------------------------------
//
// ==UserScript==
// @name           Simple eCritters Forum Tools
// @namespace      http://lkbm.ecritters.biz/
// @description    Highlight or block topics by certain users (eCritters.biz forums). Not very well done.
// @include        http://ecritters.biz/forums.php?page=viewforum&id=*
// ==/UserScript==

(function ()
{
	var hide = new Array();
	/********************************
	* List here the ids of users by whom you wish not to see topics.
	* EXAMPLE:
	*  hide[28] = 1;	// Hide topics by General Wesc (user id 28).
	*
	* Below is a working example that won't hurt anything because the user
	* id does not (and cannot) exist:
	********************************/
	hide[0] = 1;	// 0:[Not a real user]
	//hide[28] = 1;	// 28:General Wesc

	var background_change = new Array();
	/****************************************************************
	* List here the ids of user whose topics you want recoloured.
	* EXAMPLE:
	*  background_change[28] = 'red';	// Colour topics by General Wesc.
	* Here's a working example that won't hurt anything because the user
	* id does not (and cannot) exist:
	****************************************************************/
	background_change[0] = '#000000';	// 0:[Not a real user]/ #000000 (Black)

	background_change[28] = "#e0e0ff";	// 28:General Wesc (user id 28) / #f0f0ff (Light blue)
	background_change[47827] = "#f0e0e0";	// 47827:Villainous / #ffe0e0 (Violet)
	background_change[519] = "#f0fff0";	// 519:Dr. Aega	/ #f0fff0 (Light green)
	background_change[3] = "#fffcc0";	// 3:eurleif / #? (Yellow)
	background_change[22710] = "#f0f0f0";	// 22710:shroomy / #f0f0f0 (Light grey)
	background_change[49129] = "#ffe0e0";	// 49129:Truffle / #fff0f0 (Light pink)

	var trNodeList = document.evaluate('//tr', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	for(var i = 0; i < trNodeList.snapshotLength; i++)
	{
		var tr = trNodeList.snapshotItem(i);
		var s = tr.innerHTML;
		var tds = s.split("<td");
		if(tds.length == 4)
		{
			s = tds[2].replace(/.*userlookup.php.user=([0-9]*)" style="text-decoration: none;.*\n/g, "$1");
			if(hide[s])
			{
				//GM_log('Hid topic by ' + s);
				tr.style.display = 'none';
			}
			else if(background_change[s] != undefined)
			{
				//GM_log('Changed background of topic by ' + s);
				tr.style.background = background_change[s];
			}
			// Uncomment the following line to colour all topics, based on user id;
			// tr.style.background = '#' + GM_LKBM_d2h(parseInt('FFFFFF', 16) - s);
		}
	}

})();

function GM_LKBM_d2h(d)
{
	var hD="0123456789ABCDEF";
	var h = hD.substr(d&15,1);
	while(d>15)
	{
		d>>=4;
		h=hD.substr(d&15,1) + h;
	}
	return h;
}

