// ==UserScript==
// Mute and Highlight ver.1.11
// (c) 2007 by Patric Peters <me@papet.de>
// 
// Credits: Dicope (M. Dreseler <markus@dreseler.de>) fuer den get/setValue Snippet :)
// @name          Mute and Highlight Nicks
// @namespace	  http://www.papet.de
// @description   1. Sucht nach dem Nicknamen und hebt diese hervor. 2. Verbirgt Posts von Benutzern auf der Mute-Liste
// @version	      1.11 (01.07.2007)
// @include       http://forum.counter-strike.de/bb/thread.php*
// @include       http://forum.cstrike.de/bb/thread.php*
// @include       http://82.149.226.131/bb/thread.php*
// @include       http://forum.mods.de/bb/thread.php*
// ==/UserScript==

// Prompts
function conprom (e) {
  GM_setValue("hlnick", (prompt('Hervorzuhebende Nicknames eingeben, Werte mit ; trennen',GM_getValue("hlnick"))));
}
GM_registerMenuCommand("Highlight Nicks", conprom);

function conprom2 (e) {
  GM_setValue("mutenick", (prompt('Mute Nicknames eingeben, Werte mit ; trennen',GM_getValue("mutenick"))));
}
GM_registerMenuCommand("Mute Nicks", conprom2);

if(GM_getValue("hlnick") != "" || GM_getValue("mutenick") != "")
{
	// Posts
	var posts 		 = document.getElementsByTagName('td');
	var index 		 = 22;
	var countPosts   = 0;
	var countQuotes  = 0;
	var countMatches = 0;
	
	// Nicknames
	var arrNicks     = GM_getValue("hlnick").split(";");
	var arrMute      = GM_getValue("mutenick").split(";");
	
	// Regex Pattern
	var sNickPattern = arrNicks.join("|");
	var match        = eval("/("+sNickPattern+")/ig");
	var matchme      = eval("/([^#])("+sNickPattern+")([^#|</span>])/ig");
	var matchLink    = eval("/((openProfile\\(\"[0-9]*\",\\s*|src=|alt=|title=|href=)\"([^\"]*))("+sNickPattern+")([^\"]*\")/ig");
	var profile 	 = /<a href="javascript:void\(0\);" onclick='(openProfile2|openProfile)\("([^"]*)"\)'>(.*)<\/a>/ig;
	var myProfile    = eval("/<a href=\"javascript:void\\(0\\);\" onclick='(openProfile2|openProfile)\\(\"\([^\"]*\)\"\\)'>("+sNickPattern+")<\\/a>/ig");
	var matchQuote   = eval("/(Zitat von )("+sNickPattern+")/ig");
	
	// Mute Pattern
	var sNickMutePattern = arrMute.join("|");
	var profileMute 	 = eval("/<a href=\"javascript:void\\(0\\);\" onclick='(openProfile2|openProfile)\\(\"\([^\"]*\)\"\\)'>("+sNickMutePattern+")<\\/a>/ig");
	
	// Post f�r Post
	while(index < posts.length)
	{
		// Benutzerinformationen
		if(posts[index].innerHTML.match(profile) &&
		   posts[index].innerHTML.match(/reply_[0-9]*/) &&
		   posts[index].innerHTML.match(/avatare/) &&
		   !posts[index].innerHTML.match(/<\/table>/))
		{			
			// ID des Posts
			nextIndex = index + 1;
			
			// Mute
			if(arrMute[0] != "undefined" && arrMute[0] != "")
			{
				if(posts[index].innerHTML.match(profileMute))
				{
					posts[nextIndex].innerHTML = "<a style=\"cursor:pointer;\" onclick=\"document.getElementById('mute_"+nextIndex+"').style.display='block';\"><strong>- Mute -</strong></a><span id=\"mute_"+nextIndex+"\" style=\"display:none;\">"+posts[nextIndex].innerHTML+"</span>";
				}
			}
			
			// Highlight
			if(arrNicks[0] != "undefined" && arrNicks[0] != "")
			{
				// Eigener Post?
				if(posts[index].innerHTML.match(myProfile))
				{
					posts[index].innerHTML = posts[index].innerHTML.replace(myProfile,"$1<span style=\"color:00ff00;font-weight:bold;\">$3</span>$4");
					countPosts++;
				}
				else
				{
					// Quote?
					if(posts[nextIndex].innerHTML.match(matchQuote))
					{
						posts[nextIndex].innerHTML = posts[nextIndex].innerHTML.replace(matchQuote, "$1<span style=\"color:00ff00;font-weight:bold;\">$2</span>")
						countQuotes++;
					}
					
					// links entschaerfen
					var doLinks = 0;
					if(posts[nextIndex].innerHTML.match(matchLink))
					{
						posts[nextIndex].innerHTML = posts[nextIndex].innerHTML.replace(matchLink,"$1#$4#$5");
						doLinks = 1;
					}
					
					// Sonstige vorkommnisse?
					if(posts[nextIndex].innerHTML.match(matchme))
					{
						posts[nextIndex].innerHTML = posts[nextIndex].innerHTML.replace(matchme, "$1<span style=\"color:00ff00;font-weight:bold;\">$2</span>$3")
						countMatches++;
					}
					
					// Links wieder zurueckwandeln
					if(doLinks == 1)
					{
						posts[nextIndex].innerHTML = posts[nextIndex].innerHTML.replace(eval("/#("+sNickPattern+")#/ig"),"$1");
					}
				}
			}
			
			// Profil "klickbar" machen
			if(posts[index].innerHTML.match(/<a href="javascript:void\(0\);" onclick='openProfile\("([0-9]*)","([^"]*)"\)' class="onblue">(.*)<\/a>/ig))
			{
				userID = RegExp.$1;
				userSession = RegExp.$2;
				userName = RegExp.$3;
				posts[index].innerHTML = posts[index].innerHTML.replace(/<a href="javascript:void\(0\);" onclick='openProfile\("([0-9]*)","(.*)"\)' class="onblue">([^<].*)<\/a>/ig,'<a href="http://'+window.location.host+'/bb/profile.php?UID='+userID+'&SID='+userSession+'" target="_blank">'+userName+'</a>');
			}
			
			index++;
			index++;
		}
		index++;
	}
	
	// Highlight Output
	if(arrNicks[0] != "undefined" && arrNicks[0] != "")
	{
		// Output
		if(countMatches > 0 || countPosts > 0 || countQuotes > 0)
		{
			if(posts[17].innerHTML.match(/(Moderiert)/))
			{
				var sMatches = "0x";
				if(countMatches > 0)
				{
					sMatches = "<span style=\"color:00ff00;font-weight:bold;\">" + countMatches + "x</span>";
				}

				var sQuotes = "0x";
				if(countQuotes > 0)
				{
					sQuotes = "<span style=\"color:00ff00;font-weight:bold;\">" + countQuotes + "x</span>";
				}
				
				var sPosts = "0x";
				if(countPosts > 0)
				{
					sPosts = "<span style=\"color:00ff00;font-weight:bold;\">" + countPosts + "x</span>";
				}
				posts[17].innerHTML = "<br />Dein Nick kommt auf dieser Seite " + sMatches + " vor. Du wurdest " + sQuotes + " Zitiert  und hast " + sPosts + " selbst gepostet.<br /><br />" + posts[17].innerHTML;
			}
		}
	}
}