Hide Threads and Replies by Poster

Hides threads based on the player(s) that posted the thread or replied. Applies to all sub-forums, your Clan forum and your Mail. Also appplies to individual threads.

As of 2017-07-04. See the latest version.

// ==UserScript==
// @author https://greasyfork.org/en/users/85040-dan-wl-danwl
// @name Hide Threads and Replies by Poster
// @namespace daniel.church@btinternet.com
// @grant none
// @match https://www.warlight.net/*
// @description Hides threads based on the player(s) that posted the thread or replied. Applies to all sub-forums, your Clan forum and your Mail. Also appplies to individual threads.
// @version 2.1.1.11
// @license n/a
// ==/UserScript==
/*
First released on 8/12/2016 see https://www.warlight.net/Forum/222938-dans-userscript-hide-threads-replies-poster for evidence.

Copyright 2017 Daniel Church

Terms and Conditions:
Terms
i) Software. Software means the contents of this script.
ii) You. You is the person who has obtained access, installed, downloaded or wanting to benefit from this software.
iii) Use. Use means to access, install, download, copy, or benefit from using the functionality of this software. 

Conditions
1 THIS SOFTWARE AND OTHER VARIATIONS MAY NOT BE USED FOR COMMERCIAL PURPOSES UNDER ANY CIRCUMSTANCES.
2 DISTRIBUTION
2.1 THIS SOFTWARE MAY NOT BE DISTRIBUTED UNDER ANY CIRCUMSTANCES. YOU MAY MAKE A BACKUP OF THIS SOFTWARE BUT ONLY FOR ARCHIVING PURPOSES.
2.2 IF YOU DISTRIBUTE THIS SOFTWARE, YOU MAY NOT REBRAND THIS SOFTWARE.
3 MODIFICATIONS
3.1 YOU SHALL NOT MODIFY, ADAPT, TRANSLATE OR CREATE DERIVATIVE WORKS BASED UPON THE SOFTWARE UNDER ANY CIRCUMSTANCES.
3.2 YOU MUST NOT SAVE ANY MODIFICATIONS, ADAPTIONS, TRANSLATIONS OR DERIVATIVE WORKS OF THIS SOFTWARE UNDER ANY CIRCUMSTANCES.
4 THIS SOFTWARE DOES NOT GRANT ANY RIGHTS IN THE PATENTS OF CONTRIBUTORS.
5 THIS SOFTWARE AND OTHER VARIATIONS MAY ONLY BE USED IN PRIVATE.
6 THIS SOFTWARE IS SUBJECT TO CHANGE AT ANYTIME WITH OR WITHOUT WARNING.
7 THIS SOFTWARE DOES NOT GRANT TRADEMARK RIGHTS UNDER ANY CIRCUMSTANCES.
8 THIS SOFTWARE DOES NOT PROVIDE ANY WARRANTY.
9 TERMS AND CONDITIONS ARE SUBJECT TO CHANGE AT ANYTIME WITHOUT WARNING.
10 YOU ALLOW THIS SOFTWARE TO ACCESS AND MODIFY YOUR BROWSER'S LOCAL STORAGE IF YOU ALLOW THIS SOFTWARE TO RUN AND EXECUTE.
11 IF YOU AT ANY POINT DECIDE TO BREACH A CONDITION, YOU MUST REVERT YOUR ACTIONS. YOU MUST INFORM THE SOFTWARE'S CREATOR THAT YOU HAVE BREACHED A CONDITION. BY BREAKING A CONDITION, YOU MAY BE DISALLOWED TO USE THIS SOFTWARE.

BY OBTAINING ACCESS TO THIS SOFTWARE YOU AGREE TO THIS SOFTWARE'S TERMS AND CONDITIONS.
IF AT ANY POINT YOU HAD INSTALLED ANY VERSION OF THIS SOFTWARE, YOU MUST STILL ABIDE THE ABOVE TERMS AND CONDITIONS.

You may uninstall or delete this software or backup of this software if you want.
Only the author of this script may modify and save the changes of this software.

Known bugs:
Hiding all-caps subjects sometimes hides the wrong thread if the thread with the all-caps subject is downvoted.
*/

var v = '2.1.1.11';
console.log('Dan\'s userscript version: ' + v);

var userscripts =
{
	mulis: function()
	{
		console.log('window.MULIS_USERSCRIPT = ' + window.MULIS_USERSCRIPT);
		return window.MULIS_USERSCRIPT;
	}
};

function fixBlank(tag, number, newText, useLoop, updatePlayers)
{
	//makes blanked-out things visable globaly by replacing the things' innerHTML with new text

	var blank = tag[number].innerHTML.match(/\uA0/gi) || tag[number].innerHTML.match(/\uAD/gi) || tag[number].innerHTML.match(/\u2DE/gi) || tag[number].innerHTML.match(/\u00AD/gi) || tag[number].innerHTML.match(/\u02DE/gi) || tag[number].innerHTML.match(/\u1361/gi) || tag[number].innerHTML.match(/\u1680/gi) || tag[number].innerHTML.match(/\u180E/gi) || tag[number].innerHTML.match(/\u2000/gi) || tag[number].innerHTML.match(/\u2001/gi) || tag[number].innerHTML.match(/\u2002/gi) || tag[number].innerHTML.match(/\u2003/gi) || tag[number].innerHTML.match(/\u2004/gi) || tag[number].innerHTML.match(/\u2005/gi) || tag[number].innerHTML.match(/\u2006/gi) || tag[number].innerHTML.match(/\u2007/gi) || tag[number].innerHTML.match(/\u2008/gi) || tag[number].innerHTML.match(/\u2009/gi) || tag[number].innerHTML.match(/\u200A/gi) || tag[number].innerHTML.match(/\u200B/gi) || tag[number].innerHTML.match(/\u202F/gi) || tag[number].innerHTML.match(/\u205F/gi) || tag[number].innerHTML.match(/\u2800/gi) || tag[number].innerHTML.match(/\u3000/gi) || tag[number].innerHTML.match(/\u3164/gi) || tag[number].innerHTML.match(/\uFEFF/gi);

	if (useLoop)
	{
		while (number < tag.length)
		{
			if (blank)
			{
				if (tag == document.getElementsByTagName('font'))
				{
					if (tag[number].parentNode == "[object HTMLTableCellElement]" && tag[number].innerHTML != "WarLight Creator" && tag[number].innerHTML != "Script Creator")
					{
						tag[number].innerHTML = newText;
					}
				}
				else
				{
					tag[number].innerHTML = newText;
				}
			}
			number++;
		}
	}
	else
	{
		if (blank)
		{
			if (tag == document.getElementsByTagName('font'))
			{
				if (tag[number].parentNode == "[object HTMLTableCellElement]" && tag[number].innerHTML != "WarLight Creator" && tag[number].innerHTML != "Script Creator")
				{
					tag[number].innerHTML = newText;
				}
			}
			else
			{
				tag[number].innerHTML = newText;
			}
			if (updatePlayers)
			{
				localStorageChecks();
				fixPAndPsBug();
				PlayersToPThenPs();
			}
		}
	}
}

//required global vars
var	Players,
	threads,
	_threads;

//removes dublicates from localStorage
function localStorageRemoveDublicates(LSITEM)
{
	var	ObjectLS = LSITEM.split(','),
		ObjectLSNo = 0,
		ObjectLS1 = LSITEM.split(','),
		ObjectLSNo1 = 0,
		numMatches = 0;

	while (ObjectLSNo < ObjectLS.length)
	{
		ObjectLSNo == ObjectLS.length ? ObjectLSNo = 0 : '';
		while (ObjectLSNo1 < ObjectLS.length1)
		{
			if (ObjectLS[ObjectLSNo] == ObjectLS1[ObjectLSNo1])
			{
				numMatches++;
			}
			if (numMatches > 1)
			{
				//remove the dublicate
				LSITEM == localStorage.Players ? localStorage.Players = localStorage.Players.replace(ObjectLS[ObjectLSNo], '') : LSITEM == localStorage.threads ? localStorage.threads = localStorage.threads.replace(ObjectLS[ObjectLSNo], '') : localStorage._threads = localStorage._threads.replace(ObjectLS[ObjectLSNo], '');
				numMatches = 0;//reset matches
			}
			ObjectLSNo1++;
		}
		ObjectLSNo++;
	}
}

//check localStorage for players and threads
function localStorageChecks()
{
	var PlayersLS = '';

	Players = '';
	if (localStorage.getItem('Players') === undefined || localStorage.getItem('Players') === null)
	{
		localStorage.Players = '[blank name],Wally Balls,H-to-the-O-V,(((Tabby Juggernaut))),[FEL] The Prince of Felidia,';
		console.log('Currently only hiding threads and repllies by ' + localStorage.Players);
	}
	else
	{
		PlayersLS = localStorage.getItem('Players');
		//if [blank name] is being used, prevent loads of random [blank name]s from appearing
		if (PlayersLS.match(/\[blank name\]/g) !== null)
		{
			//if there's more than one [blank name], fix the bug
			if (PlayersLS.match(/\[blank name\]/g).length > 1)
			{
				localStorage.Players = PlayersLS.replace(PlayersLS.match(/\[blank name\],/), '');
				PlayersLS = localStorage.Players;
				localStorage.Players = PlayersLS.replace(PlayersLS.match(/\[blank name\]/g), '');
				localStorage.Players = '[blank name],' + localStorage.Players;
				PlayersLS = localStorage.Players;
			}
		}
		localStorageRemoveDublicates(PlayersLS);//if there's a dublicate player, remove it
		Players = PlayersLS.split(",");
	}

	//thread excepions
	var threadsLS = '';
	if (localStorage.getItem('threads') === undefined || localStorage.getItem('threads') === null || localStorage.getItem('threads') === '')
	{
		console.log('Currently no thread excetions.');
		localStorage.threads = 'localStorage.threads_first-item(do_not_remove_this)';//prevents visual UI bugs
		threads = localStorage.getItem('threads').split(',');
	}
	else
	{
		threadsLS = localStorage.getItem('threads');
		localStorageRemoveDublicates(threadsLS);//if there's a dublicate thread, remove it
		threads = threadsLS.split(',');
	}
	//console.log('localStorage.threads = ' + localStorage.threads);

	//hiding individual threads
	if (localStorage.getItem('_threads') === undefined || localStorage.getItem('_threads') === null || localStorage.getItem('_threads') === '')
	{
		console.log('currently not hiding individual threads');
		localStorage._threads = 'localStorage._threads_first-item(do_not_remove_this)';
		_threads = localStorage.getItem('threads').split(',');
	}
	else
	{
		localStorageRemoveDublicates(localStorage._threads);//if there's a dublicate thread, remove it
		_threads = localStorage.getItem('_threads').split(',');
	}

	//show/hide OT threads
	if (localStorage.getItem('DanHTRBP_hidingOT') === undefined || localStorage.getItem('DanHTRBP_hidingOT') === null)
	{
		localStorage.DanHTRBP_hidingOT = 'no';
		console.log('localStorage.DanHTRBP_hidingOT was undefined or null');
	}
	else
	{
		console.log('localStorage.DanHTRBP_hidingOT = ' + localStorage.DanHTRBP_hidingOT);
	}

	//MOTW
	if (localStorage.getItem('MOTW') === undefined || localStorage.getItem('MOTW') === null)
	{
		localStorage.MOTW = 'no';
		console.log('localStorage.MOTW was undefined or null');
	}
	else
	{
		console.log('localStorage.MOTW = ' + localStorage.MOTW);
	}

	//blank posts message
	if (localStorage.getItem('bpDialogue') === undefined || localStorage.getItem('bpDialogue') === null)
	{
		localStorage.bpDialogue = 'yes';
		console.log('localStorage.bpDialogue was undefined or null');
	}
	else
	{
		console.log('localStorage.bpDialogue = ' + localStorage.bpDialogue);
	}
}
localStorageChecks();//perform the checks

//some required global variables
var h = location.pathname,
	genF = h.includes("m/f1") || h.includes("m/F1"),
	mapF = h.includes("m/f4") || h.includes("m/F4"),
	ladF = h.includes("m/f5") || h.includes("m/F5"),
	progF = h.includes("m/f6") || h.includes("m/F6"),
	helpF = h.includes("m/f7") || h.includes("m/F7"),
	OTF = h.includes("m/f8") || h.includes("m/F8"),
	clansF = h.includes("m/f9") || h.includes("m/F9"),
	stratF = h.includes("m/f10") || h.includes("m/F10"),
	subForum = genF || mapF || ladF || progF || helpF || OTF || clansF || stratF,
	allF = h.includes("m/fo") || h.includes("m/Fo"),
	threadP =  h.includes("m/1") || h.includes("m/2") || h.includes("m/3") || h.includes("m/4") || h.includes("m/5") || h.includes("m/6") || h.includes("m/7") || h.includes("m/8") || h.includes("m/9"),
	discussionP = location.href.includes("https://www.warlight.net/Discussion/?ID="),
	mail = h.includes("/Discussion/MyMail"),
	clanF = h.includes("/Clans/forum") || h.includes("/Clans/Forum");

//prevents certain people from using all features
function isValidUser()
{
	if (document.getElementById('MailLink') === null) {return;}

	var user = document.getElementById('MailLink').nextElementSibling.href;
	var ppl =
	[
		9071760924,
		5614353942,
		3085172703
	],
	i = 0

	while (i < ppl.length)
	{
		if (user.match(ppl[i]))
		{
			break;//break the loop
			return false;//isn't a valid user
		}
		else
		{
			return true;//is a valid user
		}
		i++;
	}
}
if (!isValidUser())
{
	throw new Error();
}

var PlayersNo = 0,
	threadsNo = 0,
	_threadsNo = 0;

//Players array to another array where Players[PlayersNo] is a single var
//And Player string array (for hidden players)
var p = [],
	ps = "",
	pNo = 0;
	pS = [],
	psS = "",
	pSNo = 0;

function PlayersToPThenPs()
{
	PlayersNo = 0;
	while (PlayersNo < Players.length-1)
	{
		ps = Players[PlayersNo];
		p.push(ps);
		PlayersNo++;
	}
	pNo = 0;
	PlayersNo = 0;
	while (pNo < p.length)
	{
		psS = "\n" + p[pNo];
		pNo == p.length-1 ? psS += '.' : '';//if last item of pS, add a fullstop at the end.
		pS.push(psS);
		pNo++;
	}
	pNo = 0;
}
PlayersToPThenPs();
function fixPAndPsBug()
{
//fixes bug that causes p and pS to not reset when Player changes are made
	for (var i=Players.length-1; i>=0; i--)
	{
		p.splice(i, 1);
		pS.splice(i, 1);
	}
}
//thread exceptions
var t = [],
	ts = "",
	tNo = 0;
//thread excepions array to another array where threads[threadsNo] is a single var
function threadsToT()
{
	console.log('threads.length = ' + threads.length);
	t = [];
	ts = '';
	tNo = 0;
	while (threadsNo < threads.length)
	{
		//console.log('threads to t')
		ts = threads[threadsNo];
		t.push(ts);
		//console.log('t added; current ts:\n' + t);
		threadsNo++;
	}
	threadsNo = 0;
	console.log('t = ' + t);
	window.t = t;
}
threadsToT();

//hides individual threads
var _t = [],
	_ts = "",
	_tNo = 0;
function _threadsTo_t()
{
	console.log('_threads.length = ' + _threads.length);
	_t = [];
	_ts = '';
	_tNo = 0;
	while (_threadsNo < _threads.length)
	{
		//console.log('threads to t')
		_ts = _threads[_threadsNo];
		_t.push(_ts);
		//console.log('_t added; current _ts:\n' + _t);
		_threadsNo++;
	}
	_threadsNo = 0;
	console.log('_t = ' + _t);
	window._t = _t;
}
_threadsTo_t();

function fixThreadExceptionsBug()
{
	for (var i=threads.length-1; i>=0; i--)
	{
		t.splice(i, 1);
	}
}

//adds players/threads to the hide/exceptions list
function addToArray(ARRAY, ARRAYITEM, NUMBER)
{
	var main = typeof NUMBER == 'string';

	if (ARRAY == 'Players')
	{
		var item;

		main ? item = ' by ' + ARRAYITEM : item = ARRAYITEM.innerHTML;

		if (localStorage.Players.match(item))
		{
			//if the player is already there, don't add it
			return;
		}
		//updates and remembers Players
		main ? localStorage.Players += ARRAYITEM + ',' : localStorage.Players += ARRAYITEM.innerHTML.replace(/\u0020/, '').replace('by ', '') + ',';
		console.log('added ' + ARRAYITEM + ' to ' + ARRAY);
		fixPAndPsBug();
		localStorageChecks();
		PlayersToPThenPs();

		//updates all players buttons
		if (subForum || allF || clanF || mail)
		{
			var PlayerNameNo = 0;

			while (PlayerNameNo < PlayerName.length)
			{
				if (PlayerName[PlayerNameNo].innerHTML == item)
				{
					//make the thread visable
					PlayerName[PlayerNameNo].parentNode.parentNode.removeAttribute('class');
					PlayerName[PlayerNameNo].parentNode.parentNode.removeAttribute('style');
					//update the buttons
					PlayersBtnHCN[PlayerNameNo].style.display = 'none';
					PlayersBtnSCN[PlayerNameNo].removeAttribute('style');
				}

				PlayerNameNo++;
			}
		}

		subForum || allF || clanF || mail ? hideThreads() : '';
		threadP || discussionP ? hideReplies() : '';
	}
	else if (ARRAY == 'threads')
	{
		var item;

		main ? item = ARRAYITEM : item = ARRAYITEM.innerHTML;

		if (localStorage.threads.match(item))
		{
			//if the thread is already there, don't add it
			return;
		}
	
		//update and remember threads
		main ? localStorage.threads += ',' + ARRAYITEM : localStorage.threads += ',' + ARRAYITEM.innerHTML;
		console.log('added ' + ARRAYITEM + ' to ' + ARRAY);
		localStorageChecks();
		threadsToT();

		if (subForum || allF || clanF || mail)
		{
			//updates all thead excepions buttons
			var ThreadLinkNo = 0;

			while (ThreadLinkNo < ThreadLink.length)
			{
				if (ThreadLink[ThreadLinkNo].innerHTML == item)
				{
					ThreadExceptionsBtnHCN[ThreadLinkNo].style.display = 'none';
					ThreadExceptionsBtnSCN[ThreadLinkNo].removeAttribute('style');
				}

				ThreadLinkNo++;
			}
		}

		subForum || allF || clanF || mail ? hideThreads() : '';
	}
	else
	{
		prompt('Something went wrong... Please message Dan the following details:', 'ARRAY = ' + ARRAY);
	}
}
//removes a player from the list
function removePlayer(ARRAYITEM, NUMBER)
{
	var main = typeof NUMBER == 'string';
	var item;

	main ? item = ARRAYITEM : item = ARRAYITEM.innerHTML.replace(/\u0020/, '').replace('by ', '');

	if (localStorage.Players.match(item) === null)
	{
		//if the player isn't there, don't remove it
		return;
	}

	if (subForum || allF || clanF || mail)
	{
		main ? item = ' by ' + ARRAYITEM : item = ARRAYITEM.innerHTML;

		var PlayerNameNo = 0;

		while (PlayerNameNo < PlayerName.length)
		{
			if (PlayerName[PlayerNameNo].innerHTML == item)
			{
				//make the thread visable
				PlayerName[PlayerNameNo].parentNode.parentNode.removeAttribute('class');
				PlayerName[PlayerNameNo].parentNode.parentNode.removeAttribute('style');
				//update the buttons
				PlayersBtnSCN[PlayerNameNo].style.display = 'none';
				PlayersBtnHCN[PlayerNameNo].removeAttribute('style');
			}

			PlayerNameNo++;
		}
	}

	//redefine item
	main ? item = ARRAYITEM : item = ARRAYITEM.innerHTML.replace(/\u0020/, '').replace('by ', '');

	for (var i=Players.length-1; i>=0; i--)
	{
		if (Players[i] === item)
		{
			localStorage.Players = localStorage.Players.replace(item+",","");//update and remember Players
			//break;
		}
	}
	for (var ii=p.length-1; ii>=0; ii--)
	{
		if (p[ii] === item)
		{
			p.splice(ii, 1);
			//break;
		}
	}
	for (var iii=pS.length-1; iii>=0; iii--)
	{
		if (pS[iii] === "\n" + item)
		{
			pS.splice(iii, 1);
			//break;
		}
	}
	console.log('removed ' + item);
	localStorageChecks();
	subForum || allF || clanF || mail ? hideThreads() : '';
	threadP || discussionP ? hideReplies() : '';
}
//makes it possable to remove a thread exception
function removeThread(ARRAYITEM, NUMBER)
{
	var main = typeof NUMBER == 'string';
	var item;

	main ? item = ARRAYITEM : item = ARRAYITEM.innerHTML;

	if (localStorage.threads.match(item) === null || item == 'localStorage.threads_first-item(do_not_remove_this)')
	{
		//if the thread isn't there, don't remove it
		return;
	}

	for (var iv=threads.length-1; iv>=0; iv--)
	{
		if (threads[iv] === item)
		{
			localStorage.threads = localStorage.threads.replace(',' + item, '');//update and remember threads
			//break;
		}
	}
	for (var v=t.length-1; v>=0; v--)
	{
		if (t[v] === item)
		{
			t.splice(v, 1);
			//break;
		}
	}

	if (subForum || allF || clanF || mail)
	{
		//updates all thead excepions buttons
		var ThreadLinkNo = 0;

		while (ThreadLinkNo < ThreadLink.length)
		{
			if (ThreadLink[ThreadLinkNo].innerHTML == item)
			{
				ThreadExceptionsBtnSCN[ThreadLinkNo].style.display = 'none';
				ThreadExceptionsBtnHCN[ThreadLinkNo].removeAttribute('style');
			}

			ThreadLinkNo++;
		}
	}

	console.log('removed ' + item);
	localStorageChecks();
	subForum || allF || clanF || mail ? hideThreads() : '';
}

var config =
{
	update: function()
	{
		localStorageChecks();
		if (allF && localStorage.DanHTRBP_hidingOT == 'no')
		{
			//show OT threads and hide the downvoted OT threads
			OT.removeClassNames();
		}
		subForum || allF || clanF || mail ? hideThreads() : '';//if on forum, hide threads
		threadP || discussionP ? hideReplies() : '';//if on forum post, hide replies
	},
	advanced: function()
	{
		var	areArent;

		//hide/show OT threads
		localStorage.DanHTRBP_hidingOT == 'yes' ? areArent = 'are' : areArent = 'aren\'t';

		var DanHTRBP_hidingOT_Confirm = confirm('Currently, you ' + areArent + ' hiding OT threads. Click OK to change this.');

		DanHTRBP_hidingOT_Confirm;
		console.log('DanHTRBP_hidingOT_Confirm = ' + DanHTRBP_hidingOT_Confirm);

		if (DanHTRBP_hidingOT_Confirm)
		{
			//remembers the responce
			if (localStorage.DanHTRBP_hidingOT == 'no')
			{
				localStorage.DanHTRBP_hidingOT = 'yes';
			}
			else
			{
				localStorage.DanHTRBP_hidingOT = 'no';
			}
			config.update();
		}

		//hide/unhide MOTW threads
		localStorage.MOTW == 'yes' ? areArent = 'are' : areArent = 'aren\'t';

		var changeMOTW = confirm('Currently, you ' + areArent + ' hiding Map of the Week threads. Click OK to change this.');

		changeMOTW;
		console.log('changeMOTW = ' + changeMOTW);
		if (changeMOTW)
		{
			//remembers the responce
			if (localStorage.MOTW == 'no')
			{
				localStorage.MOTW = 'yes';
			}
			else
			{
				localStorage.MOTW = 'no';
			}
			config.update();
		}

		//hide/show blank posts messages
		localStorage.bpDialogue == 'yes' ? areArent = 'are' : areArent = 'aren\'t';

		var changeBpDialogue = confirm('Currently, you ' + areArent + ' hiding blank posts dialogues. Click OK to change this.');

		changeBpDialogue;
		if (changeBpDialogue)
		{
			//remembers the responce
			if (localStorage.bpDialogue == 'no')
			{
				localStorage.bpDialogue = 'yes';
			}
			else
			{
				localStorage.bpDialogue = 'no';
			}
			config.update();
		}
	},
	isMultiple: function(LSITEM, TEXT)
	{
		var	ObjectLS = LSITEM.split(','),
			ObjectLSNo = 0;

		while (ObjectLSNo < ObjectLS.length)
		{
			if (TEXT == ObjectLS[ObjectLSNo])
			{
				break;//prevent returning false if dublicate found
				return true;
			}
			else
			{
				return false;
			}
			ObjectLSNo++;
		}
	},
	players:
	{
		view: function()
		{
			localStorage.Players.match(',') !== null ? alert('Currently hiding posts by:' + pS) : alert('You\'re not hiding posts by anyone.');
		},
		add: function()
		{
			var newPlayer = prompt('Input a player name below.', '');

			newPlayer;

			if (newPlayer !== null && newPlayer !== '')
			{
				//if didn't press cancel and added a player name
				if (newPlayer.match(/,/))
				{
					//if the player name includes any commas, prevent the player name being added
					alert('Player names aren\'t allowed to contain commas (,).');
				}
				else if (config.isMultiple(localStorage.Players, newPlayer))
				{
					//if the player is already added, prevent it from being added again
					alert('You already have this player on your Block List');
				}
				else
				{
					addToArray('Players', newPlayer, '');//add new player to players array
					config.ui.disableButtons();//(un)disable buttons
				}
			}
		},
		remove: function()
		{
			var oldPlayer = prompt('Input a player name below.', '');

			oldPlayer;

			if (oldPlayer !== null && oldPlayer !== '')
			{
				//if didn't press cancel and added a player name, remove the player
				removePlayer(oldPlayer, '');
				config.ui.disableButtons();//(un)disable buttons
			}
		}
	},
	threads:
	{
		view: function()
		{
			localStorage.threads.match(',') !== null ? alert('Currently not hiding these threads:\n' + localStorage.threads.replace('localStorage.threads_first-item(do_not_remove_this),', '').replace('localStorage.threads_first-item(do_not_remove_this)', '')) : alert('You don\'t have any thread exceptions.');
		},
		add: function()
		{
			var newThread = prompt('Input a thread title below.', '');

			newThread;

			if (newThread !== null && newThread !== '')
			{
				//if didn't press cancel and added a thread name
				if (newThread.match(/,/))
				{
					//if the player name includes any commas, prevent the player name being added
					alert('Thread subjects aren\'t allowed to contain commas (,)');
				}
				else if (config.isMultiple(localStorage.threads, newThread))
				{
					//if the thread is already added, prevent it from being added again
					alert('You already have this thread on your Thread Exceptions');
				}
				else
				{
					addToArray('threads', newThread, '');//add thread to thread exceptions array
					config.ui.disableButtons();//(un)disable buttons
				}
			}
		},
		remove: function()
		{
			var oldThread = prompt('Input a thread title below.', '');

			oldThread;

			if (oldThread !== null && oldThread !== '')
			{
				//if didn't press cancel and added a thread name, remove the thread
				removeThread(oldThread, '');
				config.ui.disableButtons();//(un)disable buttons
			}
		}
	},
	_threads:
	{
		update: function()
		{
			localStorageChecks();//updates definition of _threads
			_threadsTo_t();//updates _t
			subForum || allF || clanF || mail ? hideThreads() : '';//refreshes threads
		},
		view: function()
		{
			localStorage._threads.match(',') !== null ? alert('Currently hiding these threads:\n' + localStorage._threads.replace('localStorage.threads_first-item(do_not_remove_this),', '').replace('localStorage.threads_first-item(do_not_remove_this)', '')) : alert('Currently not hiding any individual threads.');
		},
		add: function()
		{
			var newThread = prompt('Input a thread title below.', '');

			newThread;

			if (newThread !== null && newThread !== '')
			{
				//if didn't press cancel and added a thread name, add and remember the thread then update
				if (newThread.match(/,/))
				{
					alert('Thread subjects aren\'t allowed to contain commas (,)');
				}
				else if (config.isMultiple(localStorage._threads, newThread))
				{
					//if the thread is already added, prevent it from being added again
					alert('You already hiding this thread');
				}
				else
				{
					localStorage._threads += ',' + newThread;//add the _thread
					config._threads.update();//update _threads
					config.ui.disableButtons();//(un)disable buttons
				}
			}
		},
		remove: function()
		{
			var oldThread = prompt('Input a thread name below.', '');

			oldThread;

			if (oldThread !== null && oldThread !== '')
			{
				//if didn't press cancel and added a thread name, remember the thread then update
				if (localStorage._threads.match(oldThread) === null || oldThread =='localStorage.threads_first-item(do_not_remove_this)')
				{
					//if the thread isn't there, don't remove it
					return;
				}
				localStorage._threads = localStorage._threads.replace(',' + oldThread, '');
				config._threads.update();
				config.ui.disableButtons();//(un)disable buttons
			}
		}
	},
	toDefault: function()
	{
		//Resets players
		var resetPlayers = confirm('Reset Players?');

		resetPlayers;
		if (resetPlayers)
		{
			localStorage.removeItem('Players');
		}

		//Resets thread exceptions
		var resetThreads = confirm('Reset Thread Exceptions?');

		resetThreads;
		if (resetThreads)
		{
			localStorage.removeItem('threads');
		}

		//Resets hidden threads
		var reset_Threads = confirm('Reset Hidden Threads?');

		reset_Threads;
		if (reset_Threads)
		{
			localStorage.removeItem('_threads');
		}

		//Resets hiding off-topic threads
		var resetOT = confirm('Unhide off-topic threads?');

		resetOT;
		if (resetOT)
		{
			localStorage.removeItem('DanHTRBP_hidingOT');
		}

		//Resets hiding MOTW threads
		var resetMOTW = confirm('Unhide Map of the Week threads?');

		resetMOTW;
		if (resetMOTW)
		{
			localStorage.removeItem('MOTW');
		}

		//Resets hiding blank posts dialogues
		var resetBP = confirm('Unhide blank posts dialogues?');

		resetBP;
		if (resetBP)
		{
			localStorage.removeItem('bpDialogue');
		}

		//if anything is restored to default, update everything
		if (resetPlayers || resetThreads || reset_Threads || resetOT || resetMOTW || resetBP)
		{
			localStorageChecks();
			PlayersToPThenPs();
			threadsToT();
			_threadsTo_t();
			if (allF && resetOT && localStorage.DanHTRBP_hidingOT == 'no')
			{
				//show OT threads and hide the downvoted OT threads
				OT.removeClassNames();
			}
			subForum || allF || clanF || mail ? hideThreads() : '';//if on forum, hide threads
			threadP || discussionP ? hideReplies() : '';//if on a thread, hide replies
			config.ui.disableButtons();//(un)disable buttons
		}
	},
	ui:
	{
		createOverlays: function()
		{
			//whole UI overlay
			if (document.getElementsByClassName('overlay').length === 0)
			{
				//if an overlay doesn't exist, create one and style it
				var overlay = document.createElement('div'),
					overlayStyle = document.createElement('style');

				overlay.className = 'overlay';
				document.body.appendChild(overlay);

				overlayStyle.innerHTML = '.overlay\n{\n\tdisplay: none;\n\tbackground: white none repeat scroll 0% 0%;\n\ttop: 0;\n\tright: 0;\n\tbottom: 0;\n\ttop: 0;\n\topacity: 0.5;\n\twidth: 100%;\n\theight: 100%;\n\tposition: fixed;\n\tz-index: 98;\n}';
				document.head.appendChild(overlayStyle);

				console.log('overlay created');
			}

			document.getElementsByClassName('overlay')[0].id = 'mainOverlay';

			//parcial overlays
			var newOverlays =
				[
					document.createElement('div'),
					document.createElement('div'),
					document.createElement('div')
				],
				newOverlaysNo = 0,
				newOverlayStyle = document.createElement('style');

			newOverlayStyle.innerHTML = '.overlayParcial\n{\n\tmargin-right: -98px;\n\tposition: static !important;\n\tz-index: 100 !important;\n\tborder-radius: 5px;\n\twidth: 98px !important;\n\theight: 77px !important;\n\tfloat: left;\n}';
			document.head.appendChild(newOverlayStyle);

			var row = document.getElementsByClassName('config_dan_userscript_row');

			while (newOverlaysNo < newOverlays.length)
			{
				newOverlays[newOverlaysNo].className = 'overlay overlayParcial';
				row[newOverlaysNo].appendChild(newOverlays[newOverlaysNo]);
				row[newOverlaysNo].insertBefore(newOverlays[newOverlaysNo], row[newOverlaysNo].children[row[newOverlaysNo].children.length-2]);
				newOverlaysNo++;
			}
			console.log('created parcial overlays');

		},
		disableButtons: function()
		{
			var configbtn = document.getElementsByClassName('config_dan_userscript_button'),
				overlayParcial = document.getElementsByClassName('overlayParcial');

			window.overlayParcial = overlayParcial;

			if (localStorage.Players.match(/,/) !== null)
			{
				configbtn[2].removeAttribute('disabled');
				configbtn[2].style.cursor = "";
				overlayParcial[0].style.display = "";
			}
			else
			{
				//if no Players, disable the button
				configbtn[2].setAttribute('disabled', '');
				configbtn[2].style.cursor = 'auto';
				//add an overlay on top
				overlayParcial[0].style.display = 'block';
			}
			if (localStorage.threads.match(/,/) !== null)
			{
				configbtn[5].removeAttribute('disabled');
				configbtn[5].style.cursor = "";
				overlayParcial[1].style.display = "";
			}
			else
			{
				//if no threads, disable the button
				configbtn[5].setAttribute('disabled', '');
				configbtn[5].style.cursor = 'auto';
				//add an overlay on top
				overlayParcial[1].style.display = 'block';
			}
			if (localStorage._threads.match(/,/) !== null)
			{
				//if no Players, disable the button
				configbtn[8].removeAttribute('disabled');
				configbtn[8].style.cursor = "";
				//add an overlay on top
				overlayParcial[2].style.display = "";
			}
			else
			{
				//if no Players, disable the button
				configbtn[8].setAttribute('disabled', '');
				configbtn[8].style.cursor = 'auto';
				//add an overlay on top
				overlayParcial[2].style.display = 'block';
			}
		},
		show: function()
		{
			document.getElementById('TopRightDropDown').style.display = 'none';
			document.getElementById('mainOverlay').style.display = 'block';
			document.getElementById('config_dan_userscript').style.display = 'block';

			config.ui.disableButtons();
		},
		hide: function()
		{
			document.getElementById('config_dan_userscript').removeAttribute('style');
			document.getElementById('mainOverlay').style.display = 'none';

			overlayParcial[0].style.display = "";
			overlayParcial[1].style.display = "";
			overlayParcial[2].style.display = "";
		},
		build: function()
		{
			var newDiv =
			[
				document.createElement('div'),//main container
				document.createElement('div')//header
			];

			var newDivRow =
			[
				document.createElement('div'),//first row
				document.createElement('div'),//second row
				document.createElement('div'),//third row
				document.createElement('div')//bottom row
			];

			var uistyle = document.createElement('style');

			uistyle.innerHTML = '#config_dan_userscript\n{\n\tposition: fixed;\n\ttop: 0;\n\tright: 0;\n\tbottom: 0;\n\tleft: 0;\n\tmargin: auto;\n\tpadding: 10px;\n\tmax-width: 523px;\n\tmax-width: -webkit-fit-content;\n\tmax-width: -moz-fit-content;\n\theight: 307.5px;\n\tborder: 2px solid #000;\n\tborder-radius: 10px;\n\tbackground-color: #f00;\n\tline-height: 1.25;\n\tcolor: #fff;\n\ttext-align: center;\n\tdisplay: none;\n\tz-index: 99;\n\t}\n\n#config_dan_userscript, .config_dan_userscript_button\n{\n\tfont-family: sans-serif;\n\tfont-size: 16pt;\n}\n\n#config_dan_userscript_header\n{\nmargin-bottom: 5px;\n\twidth: 100%;\n\theight: 27.5px;\n\tfont-weight: bold;\n}\n\n.config_dan_userscript_row\n{\n\tmargin-bottom: 5px;\n\theight: 77px;\n}\n\n.config_dan_userscript_row:last-child\n{\n\theight: 27px;\n\tfloat: right;\n}\n\n.config_dan_userscript_description\n{\n\tpadding: 12.5px 0;\n\twidth: 155px;\n\tfloat: left;\n}\n\.config_dan_userscript_description_1\n{\n\tpadding: 25.5px 0;\n}\n\n.config_dan_userscript_button\n{\n\tmargin-right: 10px;\n\tpadding: 10.5px 0;\n\twidth: 98px;\n\theight: 52px;\n\tborder: 2px solid #000;\n\tborder-radius: 5px;\n\tbackground-color: #00f;\n\tcolor: #d5ffd5;\n\tcursor: pointer;\n\tfloat: left;\n}\n\n.config_dan_userscript_viewbutton\n{\n\tpadding: 23.5px 0;\n\theight: 26px;\n}\n\n.config_dan_userscript_row *:last-child\n{\n\tmargin: 0;\n\theight: 77px;\n}\n\n.config_dan_userscript_bottom\n{\n\tpadding: 0;\n\theight: 27px !important;\n\tbackground-color: #000080;\n}';
			document.head.appendChild(uistyle);

			newDiv[0].id = 'config_dan_userscript';
			document.body.appendChild(newDiv[0]);

			newDiv[1].id = 'config_dan_userscript_header';
			newDiv[1].innerHTML = 'Configure Dan\'s Userscript (v ' + v + ') Settings';
			newDiv[0].appendChild(newDiv[1]);

			newDivRow[0].className = 'config_dan_userscript_row';
			newDivRow[0].innerHTML = '<div class = "config_dan_userscript_description config_dan_userscript_description_1">Block List:</div><div class = "config_dan_userscript_button config_dan_userscript_viewbutton" onclick = "config.players.view();">View</div><div class = "config_dan_userscript_button" onclick = "config.players.add();">Add<br>Player</div><button class = "config_dan_userscript_button" onclick = "config.players.remove();">Remove<br>Player</button>';
			newDiv[0].appendChild(newDivRow[0]);

			newDivRow[1].className = 'config_dan_userscript_row';
			newDivRow[1].innerHTML = '<div class = "config_dan_userscript_description">Thread<br>Exceptions:</div><div class = "config_dan_userscript_button config_dan_userscript_viewbutton" onclick = "config.threads.view();">View</div><div class = "config_dan_userscript_button" onclick = "config.threads.add();">Add<br>Thread</div><button class = "config_dan_userscript_button" onclick = "config.threads.remove();">Remove<br>Thread</button>';
			newDiv[0].appendChild(newDivRow[1]);

			newDivRow[2].className = 'config_dan_userscript_row';
			newDivRow[2].innerHTML = '<div class = "config_dan_userscript_description">Hide these<br>threads:</div><div class = "config_dan_userscript_button config_dan_userscript_viewbutton" onclick = "config._threads.view();">View</div><div class = "config_dan_userscript_button" onclick = "config._threads.add();">Add<br>Thread</div><button class = "config_dan_userscript_button" onclick = "config._threads.remove();">Remove<br>Thread</button>';
			newDiv[0].appendChild(newDivRow[2]);

			newDivRow[3].className = 'config_dan_userscript_row';
			newDivRow[3].innerHTML = '<div class = "config_dan_userscript_button config_dan_userscript_bottom" onclick = "config.advanced();">Advanced</div><div class = "config_dan_userscript_button config_dan_userscript_bottom" onclick = "config.toDefault();">Reset</div><div class = "config_dan_userscript_button config_dan_userscript_bottom" onclick = "config.ui.hide();" style = "width: 94px;">Close</div>';
			newDiv[0].appendChild(newDivRow[3]);
		}
	}
}
config.ui.build();
config.ui.createOverlays();
window.config = config;

//main
var	sHT = document.createElement("button"),
	hT = document.createElement("button"),
	td1 = document.createElement("td"),
	li = document.createElement("li"),
	ddM = document.getElementsByClassName("dropdown-menu")[0],
	liS = li.style,
	sHTS = sHT.style,
	hTS = hT.style,
	a = document.getElementsByTagName("a"),
	aNo = "",
	f = document.getElementsByTagName("font"),
	fNo = 0,
	d = document.getElementsByTagName("tr"),
	dNo = "",
	dNoStart = '',
	dh = " detail_hidden",
	dhCN = document.getElementsByClassName(dh),
	ds = " detail_shown",
	dsCN = document.getElementsByClassName(ds),
	dg = " detail_good",
	db = "detail_blank",
	dbCN = document.getElementsByClassName(db),
	n = "none",
	y = "table-row";

window.d = d;
window.a = a;
window.dhCN = dhCN;
window.dsCN = dsCN;
window.dbCN = dbCN;

//show who's threads are getting hidden
li.id = "DansUserscriptBtn";
li.innerHTML = "Dan's Userscript";
li.onclick = function()
{
	config.ui.show();
};
liS.color = "#555";
liS.paddingTop = "3px";
liS.paddingRight = "15px";
liS.paddingBottom = "3px";
liS.paddingLeft = "15px";
liS.cursor = "pointer";
li.onmouseover = function()
{
	li.style.backgroundColor = "#08C";
	li.style.color = "#fff";
};
li.onmouseleave = function()
{
	li.style.backgroundColor = "inherit";
	li.style.color = "#555";
};
if (ddM !== undefined)
{
	ddM.appendChild(li);
	ddM.insertBefore(li, ddM.children[ddM.children.length-3]);
}

//check forum type
function checkF()
{
	//detect number of livestreams
	var	noOfStreams = 0;

	aNo = 0;

	while (aNo < a.length)
	{
		if (a[aNo].href.match(/^https:\/\/www.twitch.tv\//i) || a[aNo].innerHTML.match(/view all \d streams »/i))
		{
			//if twitch link or link to view all streams, increase no of streams
			noOfStreams++;
		}
		aNo++;
	}

	if (subForum || allF)
	{
		dNo = 4;
	}
	else
	{
		dNo = 3;
	}
	
	if (allF)
	{
		aNo = 21;
		//aNo = 20 if using muli's userscript and unity webgl;
	}
	else if (clanF || subForum || mail)
	{
		aNo = 21;
	}
	else
	{
		aNo = 20;
	}

	aNo = aNo + noOfStreams;//update the aNo depending on the amount of streams

	dNoStart = dNo;
	window.dNoStart = dNoStart;
	console.log('checkF aNo is ' + aNo + '\tcheckF dNo is ' + dNo + '\tnumber of livestreams: ' + noOfStreams);
}

//setTheadClassNames to prevent bugs
function setTheadClassNames()
{
	checkF();
	while (dNo + 1 < d.length)
	{
		if (a[aNo].href.match(/\/\Discussion\/\?ID=/i) || a[aNo].href.match(/\/\Forum\/\d/i))
		{
			a[aNo].className = "ThreadLink";
		}
		aNo++;
		dNo++;
	}
}
var ThreadLink = document.getElementsByClassName("ThreadLink");
window.ThreadLink = ThreadLink;

var TBL;

//styling info for hidden and unhidden threads
var detailShownRules;

if (allF || subForum || clanF || mail)
{
	detailShownRules = 'display: table-row;';
}
else
{
	detailShownRules = 'display: table;';
}
document.head.innerHTML += '<style id = "Hide_Show_Threads" class = "Dan_Style">.detail_hidden, .detail_blank, .OT_hidden\n{\n\tdisplay: none;\n}\n\n.detail_shown\n{\n\t'+detailShownRules+'\n}\n\n.OT_shown\n{\n\tdisplay: table-row !important;\n}\n\n.detail_shown .sub-forum, .detail_shown td[valign="middle"], .OT_shown .sub-forum, .OT_shown td[valign="middle"]\n{\n\ttext-decoration: line-through;\n}\n\n.detail_good\n{\n\tdisplay: table-row !important;\n\ttext-decoration: none !important;\n}</style>';

//hides all-caps subjects
function hideAllCaps(DNO, ANO)
{
	d[DNO].className += dh;
	a[ANO].title = 'This thread has an all-caps subject';
	console.log('DNO = ' + DNO + ' ANO = ' + ANO + ' a[ANO].innerHTML = ' + a[ANO].innerHTML + ' has an all-caps subject');
}

//vars required for UI and hide/show replies
var psttbls = [],
	psttbl = "",
	psttblNo = 0,
	cIds = [],
	cId = "",
	cIdsNo = 0;

//makes it possable to hide and show OT threads
var	OT =
{
	buttonTd: document.createElement('td'),
	buttons:
	{
		hide: document.createElement('button'),
		show: document.createElement('button')
	},
	hidden: document.getElementsByClassName('OT_hidden'),
	shown: document.getElementsByClassName('OT_shown'),
	no: (function(){return OT.hidden.length-1;}),
	show: function()
	{
		OT.buttons.hide.style.display = 'none';

		console.log('OT.no() = ' + OT.no());
		while (OT.no() < OT.hidden.length && OT.no() >= 0)
		{
			OT.hidden[OT.no()].className = OT.hidden[OT.no()].className.replace('OT_hidden', 'OT_shown');
			console.log('unhid OT thread');
			OT.no = (function(){return OT.hidden.length-1;});
		}

		OT.buttons.show.style.display = 'block';
		if (OT.shown.length > 0)
		{
			OT.shown.length > 1 ? OT.buttons.show.innerHTML = 'Hide ' + OT.shown.length + ' off-topic threads' : OT.buttons.show.innerHTML = 'Hide 1 off-topic thread';
		}
	},
	hide: function()
	{
		OT.buttons.show.style.display = 'none';

		var	subForumCN = document.getElementsByClassName('sub-forum'),
			subForumCNNo = 0;

		//search through all threads
		while (subForumCNNo < subForumCN.length)
		{
			if (subForumCN[subForumCNNo].innerHTML.includes('Off-topic'))
			{
				//if the thread is in OT, hide it
				if (subForumCN[subForumCNNo].parentNode.className.match(/OT_shown/g))
				{
					subForumCN[subForumCNNo].parentNode.className = subForumCN[subForumCNNo].parentNode.className.replace('OT_shown', 'OT_hidden');
				}
				else if (subForumCN[subForumCNNo].parentNode.className.match(/OT_hidden/g) === null)
				{
					subForumCN[subForumCNNo].parentNode.className += 'OT_hidden';
				}
				console.log('hid OT thread');
			}
			subForumCNNo++;
		}

		if (OT.hidden.length > 0)
		{
			OT.hidden.length > 1 ? OT.buttons.hide.innerHTML = 'Show ' + OT.hidden.length + ' off-topic threads' : OT.buttons.hide.innerHTML = 'Show 1 off-topic thread';
		}
		OT.buttons.hide.style.display = 'block';
	},
	removeClassNames: function()
	{
		if (allF)
		{
			checkF();
			while (dNo < d.length)
			{
				d[dNo].className = d[dNo].className.replace('OT_hidden', '').replace('OT_shown', '');
				console.log('removed OT thread class name');
				dNo++;
			}
			checkF();
		}
	}
};
window.OT = OT;
OT.buttons.hide.style.cursor = 'pointer';
OT.buttons.hide.onclick = function()
{
	OT.show();
};

OT.buttons.show.style.cursor = 'pointer';
OT.buttons.show.onclick = function()
{
	OT.hide();

};

//makes it possable to hide threads
function hideThreads()
{
	//sets thread class so that Jump to Last Page links aren't counted as threads
	setTheadClassNames();

	if (allF)
	{
		var	td = document.getElementsByTagName('td');
		var	tdNo = 0;

		while (tdNo < td.length)
		{
			//decide which tds are subforums
			if (td[tdNo].parentElement.parentElement.parentElement.className == 'region' && td[tdNo].children.length === 0 && td[tdNo].innerHTML.match(/\d/) === null && td[tdNo].innerHTML !== '')
			{
				td[tdNo].className = 'sub-forum';
				//console.log('td[' + tdNo + '] is a sub-forum');
			}
			tdNo++;
		}
		checkF();
		
	}

	//allows hiding threads from sub-forums
	if (allF)
	{
		if (localStorage.DanHTRBP_hidingOT == 'yes')
		{
				OT.hide();//hide the OT posts
				OT.buttonTd.removeAttribute('style');//show the show/hide buttons if not hiding OT posts
		}
		else
		{
			OT.buttonTd.style.display = 'none';//hide the show/hide buttons if not hiding OT posts
		}
	}
	else
	{
		OT.buttonTd.style.display = 'none';//hide the show/hide buttons if not hiding OT posts
	}

	//hide all-caps
	checkF();
	while (dNo < d.length-1)
	{
		//console.log('dNo = ' + dNo + '\naNo = ' + aNo);

		var HTRfound = false;

		if (a[aNo].href.match(/"?Offset="/gi) === null && a[aNo].innerHTML != "Jump to Last Page")
		{
			if (a[aNo].innerHTML.match(/[A-Z]/g) !== null || a[aNo].innerHTML.match(/^\d+$/) !== null)
			{
				//if letters or numbers
				if (a[aNo].innerHTML.match(/[A-Z]/g) !== null && a[aNo].innerHTML.match(/\s/g) !== null)
				{
					//if letters and spaces
					if (d[dNo].id == 'HiddenThreadsRow')
					{
						//if HiddenThreadsRow found skip it, then carry on
						//console.log('HTRfound = true; dNo = ' + dNo + '; aNo = ' + aNo);
						HTRfound = true;
						dNo++;
					}
					else
					{
						HTRfound = false;

						var punctuation = a[aNo].innerHTML.match(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g),
							main = a[aNo].innerHTML.match(/[A-Z]/g).length + a[aNo].innerHTML.match(/\s/g).length;

						var matched = false;

						//console.log('main = ' + main + '\na[' + aNo + '].innerHTML.length = ' + a[aNo].innerHTML.length);

						if (a[aNo].innerHTML.length == main)
						{
							hideAllCaps(dNo, aNo);
						}
						else
						{
							//console.log("dNo = " + dNo + " aNo = " + aNo + " a[aNo].innerHTML = " + a[aNo].innerHTML + " isn't all-caps and all-numbers");
							matched = true;
						}

						if (punctuation !== null)
						{
							if (a[aNo].innerHTML.length == main + punctuation.length)
							{
								hideAllCaps(dNo, aNo);
							}
							else
							{
								////!matched ? console.log("dNo = " + dNo + " aNo = " + aNo + " a[aNo].innerHTML = " + a[aNo].innerHTML + " isn't all-caps and all-numbers") : '';
							}
						}

						if (a[aNo].innerHTML.match(/^\d+$/) !== null)
						{
							//unhides the table row
							d[dNo].className = "";
							d[dNo].style = "";
							a[aNo].title = "";
							console.log(dNo + " " + aNo + " " + a[aNo].innerHTML + " is a number");
						}

					}
				}
			}
		}

		//turns blanked-out subjects to [blank subject] so that subject becomes visible
		fixBlank(a, aNo, '[blank subject]', false, false);

		!HTRfound ? aNo++ : '';
		!HTRfound ? dNo++ : '';
	}
	//hides threads
	checkF();
	fNo = 0;
	while (fNo < f.length)
	{
		//console.log(a[aNo].innerHTML + f[fNo].innerHTML);
		pNo = 0;
		while (pNo < p.length)
		{
			//console.log(f[fNo].innerHTML + ".includes(" + p[pNo] + ") == " + f[fNo].innerHTML.includes(p[pNo]));

			//turns blanked-out names to [blank name] so that player's name becomes visible and then hides threads by that player
			fixBlank(f, fNo, 'by [blank name]', false, true);
			//console.log(pS.length);

			if (f[fNo].innerHTML.includes(p[pNo]))
			{
				if (d[dNo].className.match(/ detail_shown/))
				{
					d[dNo].setAttribute("class", d[dNo].className.replace(' detail_shown', ' detail_hidden'));
				}
				else
				{
					d[dNo].className += dh;
				}

				d[dNo].style.display == 'table-row' ? d[dNo].removeAttribute('style') : '';
				console.log(a[aNo].innerHTML + f[fNo].innerHTML + " hidden");
			}
			pNo++;
		}
		//motw dialogue
		if (localStorage.MOTW == "yes")
		{
			//console.log(a[aNo].innerHTML + " " + d[dNo].innerHTML);
			if (a[aNo].innerHTML.includes("Map of the week discussion: Week "))
			{
				if (d[dNo].className.match(/ detail_shown/))
				{
					d[dNo].setAttribute("class", d[dNo].className.replace(' detail_shown', ' detail_hidden'));
				}
				else
				{
					d[dNo].className += dh;
				}
				a[aNo].title = "Map Of The Week is getting hidden";
			}
		}
		if (localStorage.MOTW == "no")
		{
			if (a[aNo].innerHTML.includes("Map of the week discussion: Week "))
			{
				d[dNo].className = d[dNo].className.replace(dh, '');
				a[aNo].title = "Map Of The Week isn't being hidden";
			}
		}
		fNo++;
		dNo++;
		aNo++;
	}
	fNo = 0;
	//thread exceptions
	checkF();
	tNo = 0;
	console.log('t = ' + t);
	console.log('t.length = ' + t.length);
	//if there aren't any thread exceptions, don't check for thread exceptions
	if (t.length > 1)
	{
		while (dNo < d.length-1)
		{
			if (d[dNo].id != 'HiddenThreadsRow')
			{
				tNo = 0;
				while (tNo < t.length)
				{
					//console.log('t[tNo] = ' + t[tNo]);
					if (a[aNo].innerHTML.includes(t[tNo]))
					{
						d[dNo].setAttribute("class", d[dNo].className+dg);
						a[aNo].title = "This thread is NOT being hidden";
					}
					tNo++;
				}
				aNo++;
				//prevent aNo from increasing if the hidden threads row is found as there isn't a link on the hidden threads row
			}
			dNo++;
		}
	}
	//hides individual threads
	checkF();
	_tNo = 0;
	console.log('_t = ' + _t);
	console.log('_t.length = ' + _t.length);

	if (_t.length > 1)
	{
		while (dNo < d.length-1)
		{
			if (d[dNo].id != 'HiddenThreadsRow')
			{
				_tNo = 0;
				while (_tNo < _t.length)
				{
					console.log('_t[_tNo] = ' + _t[_tNo]);
					if (a[aNo].innerHTML.includes(_t[_tNo]))
					{
						d[dNo].className += dh;
						a[aNo].title = "This thread is being hidden";
					}
					_tNo++;
				}
				aNo++;
				//prevent aNo from increasing if the hidden threads row is found as there isn't a link on the hidden threads row
			}
			dNo++;
		}
	}

	hTS.display = "none";
	if (dhCN.length > 0)
	{
		dhCN.length > 1 ? sHT.innerHTML = "Show " + dhCN.length + " hidden threads" : sHT.innerHTML = "Show 1 hidden thread";
		sHTS.display = "block";
	}
	else
	{
		sHTS.display = "none";
	}
}

//makes it possable to show hidden threads
function showHiddenThreads()
{
	console.log('showing hidden threads');

	var	dhNo = 0;

	while (dhNo < dhCN.length)
	{
		//console.log('dhCN[dhNo].className = ' + dhCN[dhNo].className);
		if (dhCN[dhNo].className.includes('OT_hidden'))
		{
			dhCN[dhNo].style.display = 'table-row';
		}
		dhCN[dhNo].setAttribute("class", dhCN[dhNo].className.replace(dh, ds));
		dhNo = dhNo;
	}

	sHTS.display = "none";
	if (dsCN.length > 0)
	{
		dsCN.length > 1 ? hT.innerHTML = "Hide " + dsCN.length + " threads" : hT.innerHTML = "Hide 1 thread";
		hTS.display = "block";
	}
	else
	{
		hTS.display = "none";
	}
	console.log('shown hidden threads');
}

//hides replies
function hideReplies()
{
	var players = [],
		player = "",
		playerNo = 0;

	aNo = 20;
	while (aNo < a.length - 18)
	{
		if (a[aNo].href.includes("warlight.net/Profile?p=") && a[aNo].parentNode == "[object HTMLTableCellElement]")
		{
			psttbl = a[aNo].parentNode.parentNode.parentNode.parentNode;
			psttbls.push(psttbl);
			player = a[aNo].innerHTML;
			players.push(player);
		}
		aNo++;
	}
	//hide main
	playerNo = 0;
	psttblNo = 0;
	while (playerNo < players.length)
	{
		pNo = 0;
		//alert(players);
		while (pNo < p.length)
		{
			if (players[playerNo].includes(p[pNo]))
			{
				if (psttbls[psttblNo].className.match(/ detail_shown/i))
				{
					psttbls[psttblNo].setAttribute('class', psttbls[psttblNo].className.replace(ds, dh));
				}
				else
				{
					psttbls[psttblNo].className += dh;
				}
			}
			pNo++;
		}
		playerNo++;
		psttblNo++;
	}
	psttblNo = 0;

	//hides show downvoted/hidden reply link if a player on the hide list has had their comment to be downvoted or hidden
	fNo = 0;
	pNo = 0;
	
	while (fNo < f.length)
	{
		pNo = 0;
		while (pNo < p.length)
		{
			if (f[fNo].innerHTML.includes('- downvoted') || f[fNo].innerHTML.includes('- hidden') && f[fNo].nextElementSibling.children[0].children[1].children[0].innerHTML.includes(p[pNo]))
			{
				f[fNo].style.display = 'none';
			}
			pNo++;
		}
		fNo++;
	}

	hTS.display = "none";
	if (dhCN.length > 0)
	{
		dhCN.length > 1 ? sHT.innerHTML = "Show " + dhCN.length + " hidden replies" : sHT.innerHTML = "Show 1 hidden reply";;
		sHTS.display = "block";
	}
	else
	{
		sHTS.display = "none";
	}
}

//shows hidden replies
function showHiddenReplies()
{
	while (psttblNo < psttbls.length)
	{
		psttbls[psttblNo].setAttribute("class", psttbls[psttblNo].className.replace(dh, ds));
		psttblNo++;
	}

	psttblNo = 0;

	sHTS.display = "none";

	if (dsCN.length > 0)
	{
		dsCN.length > 1 ? hT.innerHTML = 'Hide ' + dsCN.length + ' replies' : hT.innerHTML = 'Hide 1 reply';
		hTS.display = "block";
	}
	else
	{
		hTS.display = "none";
	}
}

function RemoveJTLPLinks()
{
	checkF();
	while (aNo < a.length)
	{
		if (a[aNo].innerHTML == 'Jump to Last Page' && a[aNo].href.match(/\?Offset=/i) !== null || a[aNo].href.match(/&Offset=/i) !== null)
		{
			//make the thread link go to the last page
			a[aNo].parentNode.children[0].href = a[aNo].href;
			//removes Jump to Last Page links - fixes many bugs
			a[aNo].remove();
			console.log('Jump to Last Page link removed');
		}
		aNo++;
	}
}

if (subForum || allF || clanF || mail)
{
	if (document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 1] !== undefined)
	{
		if (document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 1].childNodes[1] !== undefined)
		{
			if (document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 1].childNodes[1] !== undefined)
			{
				//defines where the X threads/posts hidden should be
				TBL = document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 1].childNodes[1].childNodes[0];
			}
		}
	}
	//spam
	/*if (subForum || allF)
	{
		var JTNSa = document.createElement("a"),
			td0 = document.createElement("td"),
			pages = 0;
		if (genF)
		{
			pages = 25;
			JTNSa.href = "/forum/f1-General?Offset=" + pages * 50;
		}
		if (mapF)
		{
			pages = 5;
			JTNSa.href = "/forum/f4-Map-Development?Offset=" + pages * 50;
		}
		if (ladF)
		{
			pages = 5;
			JTNSa.href = "/forum/f5-Ladder?Offset=" + pages * 50;
		}
		if (progF)
		{
			pages = 5;
			JTNSa.href = "/forum/f6-Programming?Offset=" + pages * 50;
		}
		if (helpF)
		{
			pages = 5;
			JTNSa.href = "/forum/f7-Help?Offset=" + pages * 50;
		}
		if (OTF)
		{
			pages = 20;
			JTNSa.href = "/forum/f8-topic?Offset=" + pages * 50;
		}
		if (clansF)
		{
			pages = 5;
			JTNSa.href = "/forum/f9-Clans?Offset=" + pages * 50;
		}
		if (stratF)
		{
			pages = 5;
			JTNSa.href = "/forum/f10-Strategy?Offset=" + pages * 50;
		}
		if (allF)
		{
			pages = 55;
			JTNSa.href = "/forum/Forum?Offset=" + pages * 50;
		}
		if (pages > 0)
		{
			JTNSa.innerHTML = "Jump to non-spam threads";
			td0.id = "spamTd";
			if (TBL !== undefined)
			{
				TBL.appendChild(td0);
				td0.parentNode.insertBefore(td0, td0.parentNode.childNodes[0]);
				td0.appendChild(JTNSa);
			}
		}
	}*/
	//make reset and restore buttons
	if (TBL !== undefined)
	{
		td1.id = "btnTd";
		TBL.appendChild(td1);
		td1.parentNode.insertBefore(td1, td1.parentNode.childNodes[0]);
		sHT.onclick = function()
		{
			showHiddenThreads();
		};
		sHTS.cursor = "pointer";
		td1.appendChild(sHT);
		hTS.cursor = "pointer";
		hT.onclick = function()
		{
			hideThreads();
		};

		td1.appendChild(hT);

		TBL.appendChild(OT.buttonTd);
		OT.buttonTd.parentNode.insertBefore(OT.buttonTd, OT.buttonTd.parentNode.children[1]);
		OT.buttonTd.appendChild(OT.buttons.hide);
		OT.buttonTd.appendChild(OT.buttons.show);
	}

	//makes blanked-out last post by players visable by chnaging the text to "by [blank name]"
	var s = document.getElementsByTagName("span"),
		sNo = 2;

	fixBlank(s, sNo, 'by [blank name]', true, false);

	sNo = 2;
	RemoveJTLPLinks();//removes Jump to Last Page links - fixes many bugs
	hideThreads();//hide threads straight away
}
else if (threadP || discussionP)
{
	if (document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 2] !== undefined)
	{
		if (document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 2].childNodes[1] !== undefined)
		{
			if (document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 2].childNodes[1] !== undefined)
			{
				TBL = document.getElementsByTagName("table")[document.getElementsByTagName("table").length - 2].childNodes[1].childNodes[0];
			}
		}
	}
	//turns blanked-out subjects to [blank subject] so that subject becomes visible
	fixBlank(f, fNo, '[blank subject]', true, false);
	fNo = 0;

	//makes reset and restore buttons
	if (TBL !== undefined)
	{
		td1.id = "btnTd";
		TBL.appendChild(td1);
		var btnTd = document.getElementById("btnTd");
		btnTd.parentNode.insertBefore(btnTd, btnTd.parentNode.childNodes[0]);
		sHT.onclick = function()
		{
			showHiddenReplies();
		};
		sHTS.cursor = "pointer";
		td1.appendChild(sHT);
		hTS.cursor = "pointer";
		hT.onclick = function()
		{
			hideReplies();
		};
		td1.appendChild(hT);
	}
	//hide blank posts
	var pfds = [],
		pfd = "",
		pfdNo = 0,
		divNo = 0,
		div = document.getElementsByTagName("div");
	if (document.getElementById("SubjectBox") === null && location.pathname.includes("/Discussion/Notes") === false)
	{
		while (divNo < div.length)
		{
			if (div[divNo].id.includes("PostForDisplay") && div[divNo].id != "PostForDisplay_-1")
			{
				pfd = div[divNo].id;
				pfds.push(pfd);
			}
			divNo++;
		}
		window.pfds = pfds;
		while (pfdNo < pfds.length)
		{
			if (document.getElementById(pfds[pfdNo]).innerHTML.length === 60 || document.getElementById(pfds[pfdNo]).innerHTML.length <= 121 && document.getElementById(pfds[pfdNo]).innerHTML.match(/edited/i))
			{
				var tbl = document.getElementById(pfds[pfdNo]).parentNode.parentNode.parentNode.parentNode;
				tbl.className = db;
			}
			pfdNo++;
		}
		if (localStorage.bpDialogue == 'no')
		{
			if (dbCN.length > 0)
			{
				if (dbCN.length === 1)
				{
					alert('1 blank post was hidden.');
				}
				else if (dbCN.length > 1)
				{
					alert(dbCN.length + ' blank posts were hidden.');
				}
			}
		}
	}

	//link rels
	aNo = 21;
	while (aNo < a.length - 18)
	{
		if (a[aNo].href.includes("warlight.net/wiki"))
		{
			a[aNo].rel = "help";
		}
		aNo++;
	}
	hideReplies();//hide replies straight away
}
//remove extra Muli's Userscript menu - a script causes this bug to happen
setTimeout('try{document.getElementsByClassName("userscript-menu")[1].remove();} catch(err) {}',750);
setTimeout('try{document.getElementsByClassName("userscript-menu")[1].remove();} catch(err) {}',1250);
//UI
//show and hide clicked are for making it possable to show and hide the downvoted threads an unlimited amount of time
function showClicked()
{
	$('tr[data-hidden]').show();
	var show = document.getElementById("show");
	show.id = "hide";
	var hide = document.getElementById("hide");
	hide.innerHTML = hide.innerHTML.replace("Show", "Hide");
	hide.onclick = function()
	{
		hideClicked();
	};
}

function hideClicked()
{
	$('tr[data-hidden]').hide();
	var hide = document.getElementById("hide");
	hide.id = "show";
	var show = document.getElementById("show");
	show.innerHTML = show.innerHTML.replace("Hide", "Show");
	show.onclick = function()
	{
		showClicked();
	};
}

if (subForum || allF || clanF || mail || threadP || discussionP)
{
	var f = document.getElementsByTagName("font"),
		fNo = 0;
	//makes the UI look good on the the rest of the page
	if (threadP || discussionP)
	{
		document.getElementById("MainSiteContent").childNodes[5].childNodes[1].childNodes[0].childNodes[1].childNodes[1].style.maxWidth = "1320px";//1000px + 200px +  175px + 145px
	}
	else if (mail)
	{
		document.getElementById("MainSiteContent").childNodes[3].childNodes[1].childNodes[0].childNodes[1].childNodes[1].style.maxWidth = "1320px";
	}
	else if (clanF)
	{
		document.getElementById("MainSiteContent").childNodes[8].childNodes[1].childNodes[0].childNodes[1].childNodes[1].style.maxWidth = "1320px";
	}
	else
	{
		document.getElementById("MainSiteContent").childNodes[1].childNodes[1].childNodes[0].childNodes[1].childNodes[1].style.maxWidth = "1320px";
	}
	var ActionsTh0 = document.createElement("th"),
		ActionsTh1 = document.createElement("th"),
		tdNo = 1,
		ThreadExceptionsTDCNNo = 0,
		ThreadExceptionsTrNo = 2,
		PlayersTDCNNo = 0,
		PlayersTrNo = 2;

	if (mail || clanF)
	{
		ThreadExceptionsTrNo = 2;
		PlayersTrNo = 2;
	}
	else
	{
		ThreadExceptionsTrNo = 4;
		PlayersTrNo = 4;
	}
	//UI for sub-forums, all forums, mail and clan forum (i.e. non-thread pages or non-discussion pages)

	if (threadP === false && discussionP === false)
	{
		ActionsTh0.innerHTML = 'Block List';
		ActionsTh0.style.cursor = 'pointer';
		ActionsTh0.style.minWidth = '90px';
		ActionsTh0.style.maxWidth = '90px';
		ActionsTh0.onclick = function()
		{
			config.players.view();
		};
		ActionsTh1.innerHTML = 'Thread Exceptions';
		ActionsTh1.style.cursor = 'pointer';
		ActionsTh1.style.minWidth = '145px';
		ActionsTh1.style.maxWidth = '145px';
		ActionsTh1.onclick = function()
		{
			config.threads.view();
		};
		if (mail || clanF)
		{
			d[2].appendChild(ActionsTh0);
			d[2].appendChild(ActionsTh1);
		}
		else
		{
			d[3].appendChild(ActionsTh0);
			d[3].appendChild(ActionsTh1);
		}
		//resize columns - looks better
		if (allF)
		{
			ActionsTh0.parentNode.childNodes[1].style.minWidth = "130px";
			ActionsTh0.parentNode.childNodes[1].style.maxWidth = "130px";
			ActionsTh0.parentNode.childNodes[3].style.minWidth = "33px";
			ActionsTh0.parentNode.childNodes[3].style.maxWidth = "33px";
			
		}
		else
		{
			ActionsTh0.parentNode.childNodes[1].style.minWidth = "33px";
			ActionsTh0.parentNode.childNodes[1].style.maxWidth = "33px";
		}
		setTheadClassNames();
		checkF();
		fNo = 0;
		sNo = 2;
		var HTRfound = false;
		while (dNo < d.length-1)
		{
			//if HiddenThreadsRow is found, make it possable to show and hide downvoted content an infinate amount of times
			if (d[dNo].id == "HiddenThreadsRow")
			{
				HTRfound = true;
				var htr = document.getElementById("HiddenThreadsRow"),
					show = htr.children[0].children[0];
				if (show !== null)
				{
					show.id = "show";
					show = document.getElementById("show");
					show.innerHTML = "Show " + show.innerHTML.replace("hidden", "downvoted");
				}
				var td2to6 =
				[
					document.createElement("td"),
					document.createElement("td"),
					document.createElement("td"),
					document.createElement("td"),
					document.createElement("td"),
					document.createElement("td"),
					document.createElement("td")
				];
				if (allF)
				{
					if (userscripts.mulis())
					{
						//if Muli's script enabled, hidden threads row looks quite bad, so make it look nicer
						setTimeout('var htr = document.getElementById("HiddenThreadsRow");var td2to6 = [document.createElement("td"),	document.createElement("td"),	document.createElement("td"),	document.createElement("td"),	document.createElement("td"),	document.createElement("td"),	document.createElement("td")];/*end of vars*/htr.appendChild(td2to6[0]);htr.insertBefore(td2to6[0], htr.childNodes[2]);/*remove the extra children that get created by Muli\'s script*/htr.children[((htr.children.length) - 1)].remove();htr.children[((htr.children.length) - 1)].remove();',3000);
					}
					else
					{
						//hidden threads row looks bad, so make it look nicer
						htr.appendChild(td2to6[0]);
						htr.insertBefore(td2to6[0], htr.childNodes[0]);
						htr.appendChild(td2to6[1]);
						htr.insertBefore(td2to6[1], htr.childNodes[2]);
						htr.appendChild(td2to6[2]);
						htr.insertBefore(td2to6[2], htr.children[htr.children.length-1]);
						show.parentElement.removeAttribute("colSpan");
						show.parentElement.style.textAlign = "left";
					}					
				}
				else
				{
					var htr = document.getElementById("HiddenThreadsRow"),
					tds = [document.createElement("td"), document.createElement("td"),document.createElement("td")];

					//console.log('htr.children.length = ' + htr.children.length);
					if (htr.children.length < 4)
					{
						htr.appendChild(tds[0]);
						htr.insertBefore(tds[0], htr.children[0]);
						htr.appendChild(tds[1]);
						htr.insertBefore(tds[1], htr.children[htr.children.length-1]);
						htr.appendChild(tds[2]);
						htr.insertBefore(tds[2], htr.children[htr.children.length-1]);
						show.parentElement.removeAttribute("colSpan");
						show.parentElement.style.textAlign = "left";
					}
				}

				show.onclick = function()
				{
					showClicked();
				};
				break;
			}
			//otherwise make buttons
			else if (ActionsTh0.parentNode.parentNode.childNodes[PlayersTrNo] !== undefined)
			{
				var PlayersTD = document.createElement("td"),
					PlayersHBtn = document.createElement("button"),
					PlayersSBtn = document.createElement("button");
				PlayersTD.className = "PlayersTD";
				var PlayersTDCN = document.getElementsByClassName("PlayersTD");
				ActionsTh0.parentNode.parentNode.childNodes[PlayersTrNo].appendChild(PlayersTD);
				PlayersHBtn.innerHTML = "Add";
				PlayersHBtn.className = "PlayersHBtn";
				PlayersSBtn.innerHTML = "Remove";
				PlayersSBtn.className = "PlayersSBtn";
				//decides if you get to see the hide posts or unhide posts by players button
				//preventing style getting overidden bug using matched as classname
				PlayersNo = 0;
				if (p.length < 1)
				{
					//only shows hide button
					PlayersHBtn.style.display = "table-row";
					PlayersSBtn.style.display = "none";
				}
				else
				{
					while (PlayersNo < p.length)
					{
						pNo = 0;
						while (pNo < p.length)
						{
							//alert(p[pNo]);
							if (f[fNo].innerHTML.replace("by ", "").includes(p[pNo]))
							{
								f[fNo].className = "Matched";
								//alert("dNo = " + dNo + ". p[pNo] = " + p[pNo] + ". f[fNo].innerHTML.replace('by', '') = " + f[fNo].innerHTML.replace("by ", ""));
								//alert(f[fNo].innerHTML.replace("by ", "").includes(p[pNo]));
								PlayersHBtn.style.display = "none";
								PlayersSBtn.style.display = "table-row";
							}
							if (f[fNo].className === undefined || f[fNo].className === null || f[fNo].className === "")
							{
								PlayersHBtn.style.display = "table-row";
								PlayersSBtn.style.display = "none";
							}
							pNo++;
						}
						PlayersNo++;
					}
				}
				PlayersNo = 0;
				pNo = 0;
				//came to conclusion
				PlayersTDCN[PlayersTDCNNo].appendChild(PlayersHBtn);
				PlayersTDCN[PlayersTDCNNo].appendChild(PlayersSBtn);
				PlayersTrNo++;
				PlayersTrNo++;
				PlayersTDCNNo++;
				var ThreadExceptionsTD = document.createElement("td"),
					ThreadExceptionsBtnH = document.createElement("button"),
					ThreadExceptionsBtnS = document.createElement("button");
				ThreadExceptionsTD.className = "ThreadExceptionsTD";
				var ThreadExceptionsTDCN = document.getElementsByClassName("ThreadExceptionsTD");
				ActionsTh1.parentNode.parentNode.childNodes[ThreadExceptionsTrNo].appendChild(ThreadExceptionsTD);
				ThreadExceptionsBtnH.innerHTML = "Add";
				ThreadExceptionsBtnH.className = "ThreadExceptionsBtnH";
				ThreadExceptionsBtnS.innerHTML = "Remove";
				ThreadExceptionsBtnS.className = "ThreadExceptionsBtnS";
				//decides if you get to see the add or remove a thread from thread exceptions
				if (a[aNo].title == "This thread is NOT being hidden")
				{
					ThreadExceptionsBtnH.style.display = "none";
					ThreadExceptionsBtnS.style.display = "table-row";
				}
				else
				{
					ThreadExceptionsBtnH.style.display = "table-row";
					ThreadExceptionsBtnS.style.display = "none";
				}
				//came to conclusion
				ThreadExceptionsTDCN[ThreadExceptionsTDCNNo].appendChild(ThreadExceptionsBtnH);
				ThreadExceptionsTDCN[ThreadExceptionsTDCNNo].appendChild(ThreadExceptionsBtnS);
				ThreadExceptionsTrNo++;
				ThreadExceptionsTrNo++;
				ThreadExceptionsTDCNNo++;
				f[fNo].className = "PlayerName";
				//f[fNo].innerHTML = " by 12345678901234567890123456789012345678901234567890";
				//a[aNo].innerHTML = "12345678901234567890123456789012345678901234567890";
				//s[sNo].innerHTML = "by 12345678901234567890123456789012345678901234567890";
				if (ActionsTh0.parentNode.childNodes[5].style.minWidth != "468px")
				{
					if (s[sNo] !== undefined)
					{
						if (f[fNo].innerHTML.length+s[sNo].innerHTML.length > 85)
						{
							//resize thread width to make the table look better
							//if thread poster name last replier length is greater than 85
							ActionsTh0.parentNode.childNodes[5].style.minWidth = "468px";
							ActionsTh0.parentNode.childNodes[5].style.maxWidth = "468px";
						}
					}
				}
			}
			sNo++;
			fNo++;
			aNo++;
			dNo++;
		}
		//prevent buttons being placed in the wrong place because HiddenThreadsRow is found
		if (HTRfound)
		{
			ThreadExceptionsTrNo++;
			ThreadExceptionsTrNo++;
			PlayersTrNo++;
			PlayersTrNo++;
			sNo++
			fNo++;
			while (dNo + 1 < d.length)
			{
				if (ActionsTh0.parentNode.parentNode.childNodes[ThreadExceptionsTrNo] !== undefined)
				{
					var PlayersTD = document.createElement("td"),
						PlayersHBtn = document.createElement("button"),
						PlayersSBtn = document.createElement("button");
					PlayersTD.className = "PlayersTD";
					var PlayersTDCN = document.getElementsByClassName("PlayersTD");
					ActionsTh0.parentNode.parentNode.childNodes[PlayersTrNo].appendChild(PlayersTD);
					PlayersHBtn.innerHTML = "Add";
					PlayersHBtn.className = "PlayersHBtn";
					PlayersSBtn.innerHTML = "Remove";
					PlayersSBtn.className = "PlayersSBtn";
					//decides if you get to see the hide posts or unhide posts by players button
					//prevent style getting overidden bug using matched as classname
					PlayersNo = 0;
					if (p.length < 1)
					{
						//only shows hide button
						PlayersHBtn.style.display = "table-row";
						PlayersSBtn.style.display = "none";
					}
					else
					{
						while (PlayersNo < p.length)
						{
							pNo = 0;
							while (pNo < p.length)
							{
								//alert(p[pNo]);
								if (f[fNo] !== undefined)
								{
									if (f[fNo].innerHTML.replace("by ", "").includes(p[pNo]))
									{
										f[fNo].className = "Matched";
										//alert("dNo = " + dNo + ". p[pNo] = " + p[pNo] + ". f[fNo].innerHTML.replace('by', '') = " + f[fNo].innerHTML.replace("by ", ""));
										//alert(f[fNo].innerHTML.replace("by ", "").includes(p[pNo]));
										PlayersHBtn.style.display = "none";
										PlayersSBtn.style.display = "table-row";
									}
									if (f[fNo].className === undefined || f[fNo].className === null || f[fNo].className === "")
									{
										PlayersHBtn.style.display = "table-row";
										PlayersSBtn.style.display = "none";
									}
								}
								pNo++;
							}
							PlayersNo++;
						}
					}
					PlayersNo = 0;
					pNo = 0;
					//came to conclusion
					if (f[fNo] !== undefined)
					{
						f[fNo].className = "PlayerName";
					}

					if (ActionsTh0.parentNode.childNodes[5].style.minWidth != "468px")
					{
						if (s[sNo] !== undefined)
						{
							if (f[fNo].innerHTML.length+s[sNo].innerHTML.length > 85)
							{
								//resize thread width to make the table look better
								//if thread poster name last replier length is greater than 85
								ActionsTh0.parentNode.childNodes[5].style.minWidth = "468px";
								ActionsTh0.parentNode.childNodes[5].style.maxWidth = "468px";
							}

						}
					}
					PlayersTDCN[PlayersTDCNNo].appendChild(PlayersHBtn);
					PlayersTDCN[PlayersTDCNNo].appendChild(PlayersSBtn);
					PlayersTrNo++;
					PlayersTrNo++;
					PlayersTDCNNo++;
					var ThreadExceptionsTD = document.createElement("td"),
						ThreadExceptionsBtnH = document.createElement("button"),
						ThreadExceptionsBtnS = document.createElement("button");
					ThreadExceptionsTD.className = "ThreadExceptionsTD";
					var ThreadExceptionsTDCN = document.getElementsByClassName("ThreadExceptionsTD");
					ActionsTh1.parentNode.parentNode.childNodes[ThreadExceptionsTrNo].appendChild(ThreadExceptionsTD);
					ThreadExceptionsBtnH.innerHTML = "Add";
					ThreadExceptionsBtnH.className = "ThreadExceptionsBtnH";
					ThreadExceptionsBtnS.innerHTML = "Remove";
					ThreadExceptionsBtnS.className = "ThreadExceptionsBtnS";
					//decides if you get to see the add or remove a thread from thread exceptions
					if (a[aNo].title == "This thread is NOT being hidden")
					{
						ThreadExceptionsBtnH.style.display = "none";
						ThreadExceptionsBtnS.style.display = "table-row";
					}
					else
					{
						ThreadExceptionsBtnH.style.display = "table-row";
						ThreadExceptionsBtnS.style.display = "none";
					}
					//came to conclusion
					ThreadExceptionsTDCN[ThreadExceptionsTDCNNo].appendChild(ThreadExceptionsBtnH);
					ThreadExceptionsTDCN[ThreadExceptionsTDCNNo].appendChild(ThreadExceptionsBtnS);
					ThreadExceptionsTrNo++;
					ThreadExceptionsTrNo++;
					ThreadExceptionsTDCNNo++;
					dNo++;
					aNo++;
					sNo++;
					fNo++;
				}
				else
				{
					break;
				}
			}
		}
	}

	var PlayerName = document.getElementsByClassName("PlayerName"),
		PlayersBtnHCN = document.getElementsByClassName("PlayersHBtn"),
		PlayersBtnSCN = document.getElementsByClassName("PlayersSBtn"),
		ThreadExceptionsBtnHCN = document.getElementsByClassName("ThreadExceptionsBtnH"),
		ThreadExceptionsBtnSCN = document.getElementsByClassName("ThreadExceptionsBtnS");

	//assigning onclick using loop doesn't work how it should :(
	//add player to Players array
	if (PlayersBtnHCN[0] !== undefined) {PlayersBtnHCN[0].onclick = function() {addToArray("Players", PlayerName[0], 0);};}
	if (PlayersBtnHCN[1] !== undefined) {PlayersBtnHCN[1].onclick = function() {addToArray("Players", PlayerName[1], 1);};}
	if (PlayersBtnHCN[2] !== undefined) {PlayersBtnHCN[2].onclick = function() {addToArray("Players", PlayerName[2], 2);};}
	if (PlayersBtnHCN[3] !== undefined) {PlayersBtnHCN[3].onclick = function() {addToArray("Players", PlayerName[3], 3);};}
	if (PlayersBtnHCN[4] !== undefined) {PlayersBtnHCN[4].onclick = function() {addToArray("Players", PlayerName[4], 4);};}
	if (PlayersBtnHCN[5] !== undefined) {PlayersBtnHCN[5].onclick = function() {addToArray("Players", PlayerName[5], 5);};}
	if (PlayersBtnHCN[6] !== undefined) {PlayersBtnHCN[6].onclick = function() {addToArray("Players", PlayerName[6], 6);};}
	if (PlayersBtnHCN[7] !== undefined) {PlayersBtnHCN[7].onclick = function() {addToArray("Players", PlayerName[7], 7);};}
	if (PlayersBtnHCN[8] !== undefined) {PlayersBtnHCN[8].onclick = function() {addToArray("Players", PlayerName[8], 8);};}
	if (PlayersBtnHCN[9] !== undefined) {PlayersBtnHCN[9].onclick = function() {addToArray("Players", PlayerName[9], 9);};}
	if (PlayersBtnHCN[10] !== undefined) {PlayersBtnHCN[10].onclick = function() {addToArray("Players", PlayerName[10], 10);};}
	if (PlayersBtnHCN[11] !== undefined) {PlayersBtnHCN[11].onclick = function() {addToArray("Players", PlayerName[11], 11);};}
	if (PlayersBtnHCN[12] !== undefined) {PlayersBtnHCN[12].onclick = function() {addToArray("Players", PlayerName[12], 12);};}
	if (PlayersBtnHCN[13] !== undefined) {PlayersBtnHCN[13].onclick = function() {addToArray("Players", PlayerName[13], 13);};}
	if (PlayersBtnHCN[14] !== undefined) {PlayersBtnHCN[14].onclick = function() {addToArray("Players", PlayerName[14], 14);};}
	if (PlayersBtnHCN[15] !== undefined) {PlayersBtnHCN[15].onclick = function() {addToArray("Players", PlayerName[15], 15);};}
	if (PlayersBtnHCN[16] !== undefined) {PlayersBtnHCN[16].onclick = function() {addToArray("Players", PlayerName[16], 16);};}
	if (PlayersBtnHCN[17] !== undefined) {PlayersBtnHCN[17].onclick = function() {addToArray("Players", PlayerName[17], 17);};}
	if (PlayersBtnHCN[18] !== undefined) {PlayersBtnHCN[18].onclick = function() {addToArray("Players", PlayerName[18], 18);};}
	if (PlayersBtnHCN[19] !== undefined) {PlayersBtnHCN[19].onclick = function() {addToArray("Players", PlayerName[19], 19);};}
	if (PlayersBtnHCN[20] !== undefined) {PlayersBtnHCN[20].onclick = function() {addToArray("Players", PlayerName[20], 20);};}
	if (PlayersBtnHCN[21] !== undefined) {PlayersBtnHCN[21].onclick = function() {addToArray("Players", PlayerName[21], 21);};}
	if (PlayersBtnHCN[22] !== undefined) {PlayersBtnHCN[22].onclick = function() {addToArray("Players", PlayerName[22], 22);};}
	if (PlayersBtnHCN[23] !== undefined) {PlayersBtnHCN[23].onclick = function() {addToArray("Players", PlayerName[23], 23);};}
	if (PlayersBtnHCN[24] !== undefined) {PlayersBtnHCN[24].onclick = function() {addToArray("Players", PlayerName[24], 24);};}
	if (PlayersBtnHCN[25] !== undefined) {PlayersBtnHCN[25].onclick = function() {addToArray("Players", PlayerName[25], 25);};}
	if (PlayersBtnHCN[26] !== undefined) {PlayersBtnHCN[26].onclick = function() {addToArray("Players", PlayerName[26], 26);};}
	if (PlayersBtnHCN[27] !== undefined) {PlayersBtnHCN[27].onclick = function() {addToArray("Players", PlayerName[27], 27);};}
	if (PlayersBtnHCN[28] !== undefined) {PlayersBtnHCN[28].onclick = function() {addToArray("Players", PlayerName[28], 28);};}
	if (PlayersBtnHCN[29] !== undefined) {PlayersBtnHCN[29].onclick = function() {addToArray("Players", PlayerName[29], 29);};}
	if (PlayersBtnHCN[30] !== undefined) {PlayersBtnHCN[30].onclick = function() {addToArray("Players", PlayerName[30], 30);};}
	if (PlayersBtnHCN[31] !== undefined) {PlayersBtnHCN[31].onclick = function() {addToArray("Players", PlayerName[31], 31);};}
	if (PlayersBtnHCN[32] !== undefined) {PlayersBtnHCN[32].onclick = function() {addToArray("Players", PlayerName[32], 32);};}
	if (PlayersBtnHCN[33] !== undefined) {PlayersBtnHCN[33].onclick = function() {addToArray("Players", PlayerName[33], 33);};}
	if (PlayersBtnHCN[34] !== undefined) {PlayersBtnHCN[34].onclick = function() {addToArray("Players", PlayerName[34], 34);};}
	if (PlayersBtnHCN[35] !== undefined) {PlayersBtnHCN[35].onclick = function() {addToArray("Players", PlayerName[35], 35);};}
	if (PlayersBtnHCN[36] !== undefined) {PlayersBtnHCN[36].onclick = function() {addToArray("Players", PlayerName[36], 36);};}
	if (PlayersBtnHCN[37] !== undefined) {PlayersBtnHCN[37].onclick = function() {addToArray("Players", PlayerName[37], 37);};}
	if (PlayersBtnHCN[38] !== undefined) {PlayersBtnHCN[38].onclick = function() {addToArray("Players", PlayerName[38], 38);};}
	if (PlayersBtnHCN[39] !== undefined) {PlayersBtnHCN[39].onclick = function() {addToArray("Players", PlayerName[39], 39);};}
	if (PlayersBtnHCN[40] !== undefined) {PlayersBtnHCN[40].onclick = function() {addToArray("Players", PlayerName[40], 40);};}
	if (PlayersBtnHCN[41] !== undefined) {PlayersBtnHCN[41].onclick = function() {addToArray("Players", PlayerName[41], 41);};}
	if (PlayersBtnHCN[42] !== undefined) {PlayersBtnHCN[42].onclick = function() {addToArray("Players", PlayerName[42], 42);};}
	if (PlayersBtnHCN[43] !== undefined) {PlayersBtnHCN[43].onclick = function() {addToArray("Players", PlayerName[43], 43);};}
	if (PlayersBtnHCN[44] !== undefined) {PlayersBtnHCN[44].onclick = function() {addToArray("Players", PlayerName[44], 44);};}
	if (PlayersBtnHCN[45] !== undefined) {PlayersBtnHCN[45].onclick = function() {addToArray("Players", PlayerName[45], 45);};}
	if (PlayersBtnHCN[46] !== undefined) {PlayersBtnHCN[46].onclick = function() {addToArray("Players", PlayerName[46], 46);};}
	if (PlayersBtnHCN[47] !== undefined) {PlayersBtnHCN[47].onclick = function() {addToArray("Players", PlayerName[47], 47);};}
	if (PlayersBtnHCN[48] !== undefined) {PlayersBtnHCN[48].onclick = function() {addToArray("Players", PlayerName[48], 48);};}
	if (PlayersBtnHCN[49] !== undefined) {PlayersBtnHCN[49].onclick = function() {addToArray("Players", PlayerName[49], 49);};}
	//remove player from Players array
	if (PlayersBtnSCN[0] !== undefined) {PlayersBtnSCN[0].onclick = function() {removePlayer(PlayerName[0], 0);};}
	if (PlayersBtnSCN[1] !== undefined) {PlayersBtnSCN[1].onclick = function() {removePlayer(PlayerName[1], 1);};}
	if (PlayersBtnSCN[2] !== undefined) {PlayersBtnSCN[2].onclick = function() {removePlayer(PlayerName[2], 2);};}
	if (PlayersBtnSCN[3] !== undefined) {PlayersBtnSCN[3].onclick = function() {removePlayer(PlayerName[3], 3);};}
	if (PlayersBtnSCN[4] !== undefined) {PlayersBtnSCN[4].onclick = function() {removePlayer(PlayerName[4], 4);};}
	if (PlayersBtnSCN[5] !== undefined) {PlayersBtnSCN[5].onclick = function() {removePlayer(PlayerName[5], 5);};}
	if (PlayersBtnSCN[6] !== undefined) {PlayersBtnSCN[6].onclick = function() {removePlayer(PlayerName[6], 6);};}
	if (PlayersBtnSCN[7] !== undefined) {PlayersBtnSCN[7].onclick = function() {removePlayer(PlayerName[7], 7);};}
	if (PlayersBtnSCN[8] !== undefined) {PlayersBtnSCN[8].onclick = function() {removePlayer(PlayerName[8], 8);};}
	if (PlayersBtnSCN[9] !== undefined) {PlayersBtnSCN[9].onclick = function() {removePlayer(PlayerName[9], 9);};}
	if (PlayersBtnSCN[10] !== undefined) {PlayersBtnSCN[10].onclick = function() {removePlayer(PlayerName[10], 10);};}
	if (PlayersBtnSCN[11] !== undefined) {PlayersBtnSCN[11].onclick = function() {removePlayer(PlayerName[11], 11);};}
	if (PlayersBtnSCN[12] !== undefined) {PlayersBtnSCN[12].onclick = function() {removePlayer(PlayerName[12], 12);};}
	if (PlayersBtnSCN[13] !== undefined) {PlayersBtnSCN[13].onclick = function() {removePlayer(PlayerName[13], 13);};}
	if (PlayersBtnSCN[14] !== undefined) {PlayersBtnSCN[14].onclick = function() {removePlayer(PlayerName[14], 14);};}
	if (PlayersBtnSCN[15] !== undefined) {PlayersBtnSCN[15].onclick = function() {removePlayer(PlayerName[15], 15);};}
	if (PlayersBtnSCN[16] !== undefined) {PlayersBtnSCN[16].onclick = function() {removePlayer(PlayerName[16], 16);};}
	if (PlayersBtnSCN[17] !== undefined) {PlayersBtnSCN[17].onclick = function() {removePlayer(PlayerName[17], 17);};}
	if (PlayersBtnSCN[18] !== undefined) {PlayersBtnSCN[18].onclick = function() {removePlayer(PlayerName[18], 18);};}
	if (PlayersBtnSCN[19] !== undefined) {PlayersBtnSCN[19].onclick = function() {removePlayer(PlayerName[19], 19);};}
	if (PlayersBtnSCN[20] !== undefined) {PlayersBtnSCN[20].onclick = function() {removePlayer(PlayerName[20], 20);};}
	if (PlayersBtnSCN[21] !== undefined) {PlayersBtnSCN[21].onclick = function() {removePlayer(PlayerName[21], 21);};}
	if (PlayersBtnSCN[22] !== undefined) {PlayersBtnSCN[22].onclick = function() {removePlayer(PlayerName[22], 22);};}
	if (PlayersBtnSCN[23] !== undefined) {PlayersBtnSCN[23].onclick = function() {removePlayer(PlayerName[23], 23);};}
	if (PlayersBtnSCN[24] !== undefined) {PlayersBtnSCN[24].onclick = function() {removePlayer(PlayerName[24], 24);};}
	if (PlayersBtnSCN[25] !== undefined) {PlayersBtnSCN[25].onclick = function() {removePlayer(PlayerName[25], 25);};}
	if (PlayersBtnSCN[26] !== undefined) {PlayersBtnSCN[26].onclick = function() {removePlayer(PlayerName[26], 26);};}
	if (PlayersBtnSCN[27] !== undefined) {PlayersBtnSCN[27].onclick = function() {removePlayer(PlayerName[27], 27);};}
	if (PlayersBtnSCN[28] !== undefined) {PlayersBtnSCN[28].onclick = function() {removePlayer(PlayerName[28], 28);};}
	if (PlayersBtnSCN[29] !== undefined) {PlayersBtnSCN[29].onclick = function() {removePlayer(PlayerName[29], 29);};}
	if (PlayersBtnSCN[30] !== undefined) {PlayersBtnSCN[30].onclick = function() {removePlayer(PlayerName[30], 30);};}
	if (PlayersBtnSCN[31] !== undefined) {PlayersBtnSCN[31].onclick = function() {removePlayer(PlayerName[31], 31);};}
	if (PlayersBtnSCN[32] !== undefined) {PlayersBtnSCN[32].onclick = function() {removePlayer(PlayerName[32], 32);};}
	if (PlayersBtnSCN[33] !== undefined) {PlayersBtnSCN[33].onclick = function() {removePlayer(PlayerName[33], 33);};}
	if (PlayersBtnSCN[34] !== undefined) {PlayersBtnSCN[34].onclick = function() {removePlayer(PlayerName[34], 34);};}
	if (PlayersBtnSCN[35] !== undefined) {PlayersBtnSCN[35].onclick = function() {removePlayer(PlayerName[35], 35);};}
	if (PlayersBtnSCN[36] !== undefined) {PlayersBtnSCN[36].onclick = function() {removePlayer(PlayerName[36], 36);};}
	if (PlayersBtnSCN[37] !== undefined) {PlayersBtnSCN[37].onclick = function() {removePlayer(PlayerName[37], 37);};}
	if (PlayersBtnSCN[38] !== undefined) {PlayersBtnSCN[38].onclick = function() {removePlayer(PlayerName[38], 38);};}
	if (PlayersBtnSCN[39] !== undefined) {PlayersBtnSCN[39].onclick = function() {removePlayer(PlayerName[39], 39);};}
	if (PlayersBtnSCN[40] !== undefined) {PlayersBtnSCN[40].onclick = function() {removePlayer(PlayerName[40], 40);};}
	if (PlayersBtnSCN[41] !== undefined) {PlayersBtnSCN[41].onclick = function() {removePlayer(PlayerName[41], 41);};}
	if (PlayersBtnSCN[42] !== undefined) {PlayersBtnSCN[42].onclick = function() {removePlayer(PlayerName[42], 42);};}
	if (PlayersBtnSCN[43] !== undefined) {PlayersBtnSCN[43].onclick = function() {removePlayer(PlayerName[43], 43);};}
	if (PlayersBtnSCN[44] !== undefined) {PlayersBtnSCN[44].onclick = function() {removePlayer(PlayerName[44], 44);};}
	if (PlayersBtnSCN[45] !== undefined) {PlayersBtnSCN[45].onclick = function() {removePlayer(PlayerName[45], 45);};}
	if (PlayersBtnSCN[46] !== undefined) {PlayersBtnSCN[46].onclick = function() {removePlayer(PlayerName[46], 46);};}
	if (PlayersBtnSCN[47] !== undefined) {PlayersBtnSCN[47].onclick = function() {removePlayer(PlayerName[47], 47);};}
	if (PlayersBtnSCN[48] !== undefined) {PlayersBtnSCN[48].onclick = function() {removePlayer(PlayerName[48], 48);};}
	if (PlayersBtnSCN[49] !== undefined) {PlayersBtnSCN[49].onclick = function() {removePlayer(PlayerName[49], 49);};}
	//add thread to thread exceptions array
	if (ThreadExceptionsBtnHCN[0] !== undefined) {ThreadExceptionsBtnHCN[0].onclick = function() {addToArray("threads", ThreadLink[0], 0);};}
	if (ThreadExceptionsBtnHCN[1] !== undefined) {ThreadExceptionsBtnHCN[1].onclick = function() {addToArray("threads", ThreadLink[1], 1);};}
	if (ThreadExceptionsBtnHCN[2] !== undefined) {ThreadExceptionsBtnHCN[2].onclick = function() {addToArray("threads", ThreadLink[2], 2);};}
	if (ThreadExceptionsBtnHCN[3] !== undefined) {ThreadExceptionsBtnHCN[3].onclick = function() {addToArray("threads", ThreadLink[3], 3);};}
	if (ThreadExceptionsBtnHCN[4] !== undefined) {ThreadExceptionsBtnHCN[4].onclick = function() {addToArray("threads", ThreadLink[4], 4);};}
	if (ThreadExceptionsBtnHCN[5] !== undefined) {ThreadExceptionsBtnHCN[5].onclick = function() {addToArray("threads", ThreadLink[5], 5);};}
	if (ThreadExceptionsBtnHCN[6] !== undefined) {ThreadExceptionsBtnHCN[6].onclick = function() {addToArray("threads", ThreadLink[6], 6);};}
	if (ThreadExceptionsBtnHCN[7] !== undefined) {ThreadExceptionsBtnHCN[7].onclick = function() {addToArray("threads", ThreadLink[7], 7);};}
	if (ThreadExceptionsBtnHCN[8] !== undefined) {ThreadExceptionsBtnHCN[8].onclick = function() {addToArray("threads", ThreadLink[8], 8);};}
	if (ThreadExceptionsBtnHCN[9] !== undefined) {ThreadExceptionsBtnHCN[9].onclick = function() {addToArray("threads", ThreadLink[9], 9);};}
	if (ThreadExceptionsBtnHCN[10] !== undefined) {ThreadExceptionsBtnHCN[10].onclick = function() {addToArray("threads", ThreadLink[10], 10);};}
	if (ThreadExceptionsBtnHCN[11] !== undefined) {ThreadExceptionsBtnHCN[11].onclick = function() {addToArray("threads", ThreadLink[11], 11);};}
	if (ThreadExceptionsBtnHCN[12] !== undefined) {ThreadExceptionsBtnHCN[12].onclick = function() {addToArray("threads", ThreadLink[12], 12);};}
	if (ThreadExceptionsBtnHCN[13] !== undefined) {ThreadExceptionsBtnHCN[13].onclick = function() {addToArray("threads", ThreadLink[13], 13);};}
	if (ThreadExceptionsBtnHCN[14] !== undefined) {ThreadExceptionsBtnHCN[14].onclick = function() {addToArray("threads", ThreadLink[14], 14);};}
	if (ThreadExceptionsBtnHCN[15] !== undefined) {ThreadExceptionsBtnHCN[15].onclick = function() {addToArray("threads", ThreadLink[15], 15);};}
	if (ThreadExceptionsBtnHCN[16] !== undefined) {ThreadExceptionsBtnHCN[16].onclick = function() {addToArray("threads", ThreadLink[16], 16);};}
	if (ThreadExceptionsBtnHCN[17] !== undefined) {ThreadExceptionsBtnHCN[17].onclick = function() {addToArray("threads", ThreadLink[17], 17);};}
	if (ThreadExceptionsBtnHCN[18] !== undefined) {ThreadExceptionsBtnHCN[18].onclick = function() {addToArray("threads", ThreadLink[18], 18);};}
	if (ThreadExceptionsBtnHCN[19] !== undefined) {ThreadExceptionsBtnHCN[19].onclick = function() {addToArray("threads", ThreadLink[19], 19);};}
	if (ThreadExceptionsBtnHCN[20] !== undefined) {ThreadExceptionsBtnHCN[20].onclick = function() {addToArray("threads", ThreadLink[20], 20);};}
	if (ThreadExceptionsBtnHCN[21] !== undefined) {ThreadExceptionsBtnHCN[21].onclick = function() {addToArray("threads", ThreadLink[21], 21);};}
	if (ThreadExceptionsBtnHCN[22] !== undefined) {ThreadExceptionsBtnHCN[22].onclick = function() {addToArray("threads", ThreadLink[22], 22);};}
	if (ThreadExceptionsBtnHCN[23] !== undefined) {ThreadExceptionsBtnHCN[23].onclick = function() {addToArray("threads", ThreadLink[23], 23);};}
	if (ThreadExceptionsBtnHCN[24] !== undefined) {ThreadExceptionsBtnHCN[24].onclick = function() {addToArray("threads", ThreadLink[24], 24);};}
	if (ThreadExceptionsBtnHCN[25] !== undefined) {ThreadExceptionsBtnHCN[25].onclick = function() {addToArray("threads", ThreadLink[25], 25);};}
	if (ThreadExceptionsBtnHCN[26] !== undefined) {ThreadExceptionsBtnHCN[26].onclick = function() {addToArray("threads", ThreadLink[26], 26);};}
	if (ThreadExceptionsBtnHCN[27] !== undefined) {ThreadExceptionsBtnHCN[27].onclick = function() {addToArray("threads", ThreadLink[27], 27);};}
	if (ThreadExceptionsBtnHCN[28] !== undefined) {ThreadExceptionsBtnHCN[28].onclick = function() {addToArray("threads", ThreadLink[28], 28);};}
	if (ThreadExceptionsBtnHCN[29] !== undefined) {ThreadExceptionsBtnHCN[29].onclick = function() {addToArray("threads", ThreadLink[29], 29);};}
	if (ThreadExceptionsBtnHCN[30] !== undefined) {ThreadExceptionsBtnHCN[30].onclick = function() {addToArray("threads", ThreadLink[30], 30);};}
	if (ThreadExceptionsBtnHCN[31] !== undefined) {ThreadExceptionsBtnHCN[31].onclick = function() {addToArray("threads", ThreadLink[31], 31);};}
	if (ThreadExceptionsBtnHCN[32] !== undefined) {ThreadExceptionsBtnHCN[32].onclick = function() {addToArray("threads", ThreadLink[32], 32);};}
	if (ThreadExceptionsBtnHCN[33] !== undefined) {ThreadExceptionsBtnHCN[33].onclick = function() {addToArray("threads", ThreadLink[33], 33);};}
	if (ThreadExceptionsBtnHCN[34] !== undefined) {ThreadExceptionsBtnHCN[34].onclick = function() {addToArray("threads", ThreadLink[34], 34);};}
	if (ThreadExceptionsBtnHCN[35] !== undefined) {ThreadExceptionsBtnHCN[35].onclick = function() {addToArray("threads", ThreadLink[35], 35);};}
	if (ThreadExceptionsBtnHCN[36] !== undefined) {ThreadExceptionsBtnHCN[36].onclick = function() {addToArray("threads", ThreadLink[36], 36);};}
	if (ThreadExceptionsBtnHCN[37] !== undefined) {ThreadExceptionsBtnHCN[37].onclick = function() {addToArray("threads", ThreadLink[37], 37);};}
	if (ThreadExceptionsBtnHCN[38] !== undefined) {ThreadExceptionsBtnHCN[38].onclick = function() {addToArray("threads", ThreadLink[38], 38);};}
	if (ThreadExceptionsBtnHCN[39] !== undefined) {ThreadExceptionsBtnHCN[39].onclick = function() {addToArray("threads", ThreadLink[39], 39);};}
	if (ThreadExceptionsBtnHCN[40] !== undefined) {ThreadExceptionsBtnHCN[40].onclick = function() {addToArray("threads", ThreadLink[40], 40);};}
	if (ThreadExceptionsBtnHCN[41] !== undefined) {ThreadExceptionsBtnHCN[41].onclick = function() {addToArray("threads", ThreadLink[41], 41);};}
	if (ThreadExceptionsBtnHCN[42] !== undefined) {ThreadExceptionsBtnHCN[42].onclick = function() {addToArray("threads", ThreadLink[42], 42);};}
	if (ThreadExceptionsBtnHCN[43] !== undefined) {ThreadExceptionsBtnHCN[43].onclick = function() {addToArray("threads", ThreadLink[43], 43);};}
	if (ThreadExceptionsBtnHCN[44] !== undefined) {ThreadExceptionsBtnHCN[44].onclick = function() {addToArray("threads", ThreadLink[44], 44);};}
	if (ThreadExceptionsBtnHCN[45] !== undefined) {ThreadExceptionsBtnHCN[45].onclick = function() {addToArray("threads", ThreadLink[45], 45);};}
	if (ThreadExceptionsBtnHCN[46] !== undefined) {ThreadExceptionsBtnHCN[46].onclick = function() {addToArray("threads", ThreadLink[46], 46);};}
	if (ThreadExceptionsBtnHCN[47] !== undefined) {ThreadExceptionsBtnHCN[47].onclick = function() {addToArray("threads", ThreadLink[47], 47);};}
	if (ThreadExceptionsBtnHCN[48] !== undefined) {ThreadExceptionsBtnHCN[48].onclick = function() {addToArray("threads", ThreadLink[48], 48);};}
	if (ThreadExceptionsBtnHCN[49] !== undefined) {ThreadExceptionsBtnHCN[49].onclick = function() {addToArray("threads", ThreadLink[49], 49);};}
	//remove thread exception from thread exceptions array
	if (ThreadExceptionsBtnSCN[0] !== undefined) {ThreadExceptionsBtnSCN[0].onclick = function() {removeThread(ThreadLink[0], 0);};}
	if (ThreadExceptionsBtnSCN[1] !== undefined) {ThreadExceptionsBtnSCN[1].onclick = function() {removeThread(ThreadLink[1], 1);};}
	if (ThreadExceptionsBtnSCN[2] !== undefined) {ThreadExceptionsBtnSCN[2].onclick = function() {removeThread(ThreadLink[2], 2);};}
	if (ThreadExceptionsBtnSCN[3] !== undefined) {ThreadExceptionsBtnSCN[3].onclick = function() {removeThread(ThreadLink[3], 3);};}
	if (ThreadExceptionsBtnSCN[4] !== undefined) {ThreadExceptionsBtnSCN[4].onclick = function() {removeThread(ThreadLink[4], 4);};}
	if (ThreadExceptionsBtnSCN[5] !== undefined) {ThreadExceptionsBtnSCN[5].onclick = function() {removeThread(ThreadLink[5], 5);};}
	if (ThreadExceptionsBtnSCN[6] !== undefined) {ThreadExceptionsBtnSCN[6].onclick = function() {removeThread(ThreadLink[6], 6);};}
	if (ThreadExceptionsBtnSCN[7] !== undefined) {ThreadExceptionsBtnSCN[7].onclick = function() {removeThread(ThreadLink[7], 7);};}
	if (ThreadExceptionsBtnSCN[8] !== undefined) {ThreadExceptionsBtnSCN[8].onclick = function() {removeThread(ThreadLink[8], 8);};}
	if (ThreadExceptionsBtnSCN[9] !== undefined) {ThreadExceptionsBtnSCN[9].onclick = function() {removeThread(ThreadLink[9], 9);};}
	if (ThreadExceptionsBtnSCN[10] !== undefined) {ThreadExceptionsBtnSCN[10].onclick = function() {removeThread(ThreadLink[10], 10);};}
	if (ThreadExceptionsBtnSCN[11] !== undefined) {ThreadExceptionsBtnSCN[11].onclick = function() {removeThread(ThreadLink[11], 11);};}
	if (ThreadExceptionsBtnSCN[12] !== undefined) {ThreadExceptionsBtnSCN[12].onclick = function() {removeThread(ThreadLink[12], 12);};}
	if (ThreadExceptionsBtnSCN[13] !== undefined) {ThreadExceptionsBtnSCN[13].onclick = function() {removeThread(ThreadLink[13], 13);};}
	if (ThreadExceptionsBtnSCN[14] !== undefined) {ThreadExceptionsBtnSCN[14].onclick = function() {removeThread(ThreadLink[14], 14);};}
	if (ThreadExceptionsBtnSCN[15] !== undefined) {ThreadExceptionsBtnSCN[15].onclick = function() {removeThread(ThreadLink[15], 15);};}
	if (ThreadExceptionsBtnSCN[16] !== undefined) {ThreadExceptionsBtnSCN[16].onclick = function() {removeThread(ThreadLink[16], 16);};}
	if (ThreadExceptionsBtnSCN[17] !== undefined) {ThreadExceptionsBtnSCN[17].onclick = function() {removeThread(ThreadLink[17], 17);};}
	if (ThreadExceptionsBtnSCN[18] !== undefined) {ThreadExceptionsBtnSCN[18].onclick = function() {removeThread(ThreadLink[18], 18);};}
	if (ThreadExceptionsBtnSCN[19] !== undefined) {ThreadExceptionsBtnSCN[19].onclick = function() {removeThread(ThreadLink[19], 19);};}
	if (ThreadExceptionsBtnSCN[20] !== undefined) {ThreadExceptionsBtnSCN[20].onclick = function() {removeThread(ThreadLink[20], 20);};}
	if (ThreadExceptionsBtnSCN[21] !== undefined) {ThreadExceptionsBtnSCN[21].onclick = function() {removeThread(ThreadLink[21], 21);};}
	if (ThreadExceptionsBtnSCN[22] !== undefined) {ThreadExceptionsBtnSCN[22].onclick = function() {removeThread(ThreadLink[22], 22);};}
	if (ThreadExceptionsBtnSCN[23] !== undefined) {ThreadExceptionsBtnSCN[23].onclick = function() {removeThread(ThreadLink[23], 23);};}
	if (ThreadExceptionsBtnSCN[24] !== undefined) {ThreadExceptionsBtnSCN[24].onclick = function() {removeThread(ThreadLink[24], 24);};}
	if (ThreadExceptionsBtnSCN[25] !== undefined) {ThreadExceptionsBtnSCN[25].onclick = function() {removeThread(ThreadLink[25], 25);};}
	if (ThreadExceptionsBtnSCN[26] !== undefined) {ThreadExceptionsBtnSCN[26].onclick = function() {removeThread(ThreadLink[26], 26);};}
	if (ThreadExceptionsBtnSCN[27] !== undefined) {ThreadExceptionsBtnSCN[27].onclick = function() {removeThread(ThreadLink[27], 27);};}
	if (ThreadExceptionsBtnSCN[28] !== undefined) {ThreadExceptionsBtnSCN[28].onclick = function() {removeThread(ThreadLink[28], 28);};}
	if (ThreadExceptionsBtnSCN[29] !== undefined) {ThreadExceptionsBtnSCN[29].onclick = function() {removeThread(ThreadLink[29], 29);};}
	if (ThreadExceptionsBtnSCN[30] !== undefined) {ThreadExceptionsBtnSCN[30].onclick = function() {removeThread(ThreadLink[30], 30);};}
	if (ThreadExceptionsBtnSCN[31] !== undefined) {ThreadExceptionsBtnSCN[31].onclick = function() {removeThread(ThreadLink[31], 31);};}
	if (ThreadExceptionsBtnSCN[32] !== undefined) {ThreadExceptionsBtnSCN[32].onclick = function() {removeThread(ThreadLink[32], 32);};}
	if (ThreadExceptionsBtnSCN[33] !== undefined) {ThreadExceptionsBtnSCN[33].onclick = function() {removeThread(ThreadLink[33], 33);};}
	if (ThreadExceptionsBtnSCN[34] !== undefined) {ThreadExceptionsBtnSCN[34].onclick = function() {removeThread(ThreadLink[34], 34);};}
	if (ThreadExceptionsBtnSCN[35] !== undefined) {ThreadExceptionsBtnSCN[35].onclick = function() {removeThread(ThreadLink[35], 35);};}
	if (ThreadExceptionsBtnSCN[36] !== undefined) {ThreadExceptionsBtnSCN[36].onclick = function() {removeThread(ThreadLink[36], 36);};}
	if (ThreadExceptionsBtnSCN[37] !== undefined) {ThreadExceptionsBtnSCN[37].onclick = function() {removeThread(ThreadLink[37], 37);};}
	if (ThreadExceptionsBtnSCN[38] !== undefined) {ThreadExceptionsBtnSCN[38].onclick = function() {removeThread(ThreadLink[38], 38);};}
	if (ThreadExceptionsBtnSCN[39] !== undefined) {ThreadExceptionsBtnSCN[39].onclick = function() {removeThread(ThreadLink[39], 39);};}
	if (ThreadExceptionsBtnSCN[40] !== undefined) {ThreadExceptionsBtnSCN[40].onclick = function() {removeThread(ThreadLink[40], 40);};}
	if (ThreadExceptionsBtnSCN[41] !== undefined) {ThreadExceptionsBtnSCN[41].onclick = function() {removeThread(ThreadLink[41], 41);};}
	if (ThreadExceptionsBtnSCN[42] !== undefined) {ThreadExceptionsBtnSCN[42].onclick = function() {removeThread(ThreadLink[42], 42);};}
	if (ThreadExceptionsBtnSCN[43] !== undefined) {ThreadExceptionsBtnSCN[43].onclick = function() {removeThread(ThreadLink[43], 43);};}
	if (ThreadExceptionsBtnSCN[44] !== undefined) {ThreadExceptionsBtnSCN[44].onclick = function() {removeThread(ThreadLink[44], 44);};}
	if (ThreadExceptionsBtnSCN[45] !== undefined) {ThreadExceptionsBtnSCN[45].onclick = function() {removeThread(ThreadLink[45], 45);};}
	if (ThreadExceptionsBtnSCN[46] !== undefined) {ThreadExceptionsBtnSCN[46].onclick = function() {removeThread(ThreadLink[46], 46);};}
	if (ThreadExceptionsBtnSCN[47] !== undefined) {ThreadExceptionsBtnSCN[47].onclick = function() {removeThread(ThreadLink[47], 47);};}
	if (ThreadExceptionsBtnSCN[48] !== undefined) {ThreadExceptionsBtnSCN[48].onclick = function() {removeThread(ThreadLink[48], 48);};}
	if (ThreadExceptionsBtnSCN[49] !== undefined) {ThreadExceptionsBtnSCN[49].onclick = function() {removeThread(ThreadLink[49], 49);};}
}

//makes blanked-out links visable globaly by replacing the link's innerHTML with [blank name]
var a = document.getElementsByTagName("a"),
	aNo = 0;

fixBlank(a, aNo, '[blank name]', true, false);

//makes the site's style look better

var styles = 
[
	document.createElement('style'),
	document.createElement('style'),
	document.createElement('style')
];

var windowInnerWidth =
{
	is: function()
	{
		console.log('window.innerWidth is ' + window.innerWidth);
	},

	start: function()
	{
		setInterval(windowInnerWidth.is, 500);
		return this;
	},

	stop: function()
	{
		clearInterval(windowInnerWidth.start);
		return this;
	}
}

window.windowInnerWidth = windowInnerWidth;
//allows easier testing with window inner width

var	subForum = location.href.match(/^https:\/\/www.\warlight\.net\/forum\/f1/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/f4/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/f5/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/f6/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/f7/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/f8/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/f9/i) || location.href.match(/^https:\/\/www.\warlight\.net\/clans\/forum/i) || location.href.match(/^https:\/\/www.\warlight\.net\/Discussion\/MyMail/i),
	allForum = location.href.match(/^https:\/\/www.\warlight\.net\/forum\/forum/i),
	postPage = location.href.match(/^https:\/\/www.\warlight\.net\/forum\/1/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/2/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/3/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/4/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/5/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/6/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/7/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/8/i) || location.href.match(/^https:\/\/www.\warlight\.net\/forum\/9/i) || location.href.match(/^https:\/\/www.\warlight\.net\/Discussion\/\?ID=/i),
	flashPage = location.href.match(/^https:\/\/www.\warlight\.net\/MultiPlayer\?/i) || location.href.match(/^https:\/\/www.\warlight\.net\/SinglePlayer\?/i);

function mainCss()
{
	var regionCss = '.region\n{\n\tmax-width: '+(screen.width-20-6-14-22)+'px !important;\n\twidth: 100%;\n}\n\n',
		regionTdCss = '#MainSiteContent table tr td\n{\n\tvertical-align: middle; !important\n}\n\n',
		tableRegionTrCss = 'table.region tr\n{\n\tbackground-color: #151515;\n\tbackground: -o-linear-gradient(#353535, #151515) !important;\n\t-moz-background: linear-gradient(#353535, #151515) !important;\n\tbackground: -webkit-linear-gradient(#353535, #151515) !important;\n\tbackground: linear-gradient(#353535, #151515) !important;\n\tborder-right: 1px solid #333333;\n\tborder-bottom: 1px solid #fff;\n\tborder-left: 1px solid #333333;\n}\n\n',
		tableRegionTrHighlightedCss = '/*highlighting*/\ntable.region tr[style*="background-color"]\n{\n\tbackground-color: #4f4f4f !important;\n\tbackground: -webkit-linear-gradient(rgb(55,55,55) 7%, #4f4f4f 93%) !important;\n\tbackground: -moz-linear-gradient(rgb(55,55,55) 7%, #4f4f4f 93%) !important;\n\tbackground: -o-linear-gradient(rgb(55,55,55) 7%, #4f4f4f 93%) !important;\n\tbackground: linear-gradient(rgb(55,55,55) 7%, #4f4f4f 93%) !important;\n}\n\n',
		uiTabsPanelTableCss = '.ui-tabs-panel table\n{\n\twidth: 100%;\n}\n\n',
		uiTabsPanelTableTdCss = '.ui-tabs-panel table td\n{\n\t/*width: 48%;*/\n}\n\n',
		tableDataTableCss = 'table.dataTable\n{\n\twidth: 100%;\n\tvertical-align: top;\n\tborder-top-right-radius: 8px;\n\tborder-top-left-radius: 8px;\n\tbackground-color: #171717;\n\tborder-top: 0;\n\tborder-left: 0;\n\tborder-right: 0;\n}\n\n',
		tableDataTableTheadCss = 'table.dataTable thead\n{\n\tletter-spacing: 1px;\n\theight: 45px;\n}\n\n',
		tableDataTableTheadTrTdChildrenCss = 'table.dataTable thead tr td, .showGames table.dataTable thead tr, .followMeBar\n{\n\tbackground-color: #65171B !important;\n\tbackground: -o-linear-gradient(#65171B, #490104) !important;\n\tbackground: -moz-linear-gradient(#65171B, #490104) !important;\n\tbackground: -webkit-linear-gradient(#65171B, #490104) !important;\n\tbackground: linear-gradient(#65171B, #490104) !important;\n\tborder-top: 1px solid #333;\n\tborder-bottom: 1px solid #444 !important;\n\tcolor: #fff;\n}\n\n',
		tableDataTableTheadTrTdFirstChildCss = 'table.dataTable thead tr td:first-child\n{\n\tborder-top-left-radius: 10px;\n\ttext-shadow: 1px 1px 1px #000;\n}\n\n',
		tableDataTableTheadTrTdLastChildCss = 'table.dataTable thead tr td:last-child\n{\n\tborder-top-right-radius: 10px;\n\ttext-shadow: 2px 2px 2px #000;\n}\n\n',
		tableDataTableTrCss = 'table.dataTable tr\n{\n\tbackground-color: #151515;\n\tbackground: -o-linear-gradient(#353535, #151515) !important;\n\t-moz-background: linear-gradient(#353535, #151515) !important;\n\tbackground: -webkit-linear-gradient(#353535, #151515) !important;\n\tbackground: linear-gradient(#353535, #151515) !important;\n\tborder-right: 1px solid #333;\n\tborder-bottom: 1px solid #fff;\n\tborder-left: 1px solid #333;\n}\n\n',
		tableDataTableSpanCss = 'table.dataTable span\n{\n\tborder-top-right-radius: 6px;\n\tborder-top-left-radius: 6px;\n\tborder-bottom-right-radius: 6px;\n\tborder-bottom-left-radius: 6px;\n\tborder: 0px solid #333;\n}\n\n',
		tableDataTableSpanSpanCss = 'table.dataTable span span\n{\n\tborder: 0px solid #333;\n}\n\n',
		tableDataTableTdCss = 'table.dataTable td\n{\n\tpadding: 5px 6px 5px 6px;\n\tborder-collapse: collapse;\n\tborder-bottom: 1px solid #444;\n}\n\n',
		tdDataTableTitleRowCss = 'td.dataTableTitleRow\n{\n\tbackground-color: #300;\n\tborder-top-right-radius: 8px;\n\tborder-top-left-radius: 8px;\n}\n\n',
		MainSiteContentTableFirstOfTypeCss = '#MainSiteContent > table:first-of-type\n{\n\tvertical-align: top;\n\twidth: 100%;\n}\n\n',
		MainSiteContentDivCss = '#MainSiteContent div\n{\n\tvertical-align: top;\n\tmax-width: none !important;\n}\n\n',
		MainSiteContentTableTrTdCss = '#MainSiteContent table tr td\n{\n\tvertical-align: middle;\n}\n\n',
		//LivestreamContainerCss = '#LivestreamContainer\n{\n\tposition: static;\n}\n\n',
		TopRightBarCorrectionsCss = '.TopRightBar div *\n{\n\tposition: relative;\n\ttop: -1px;\n}\n\n#MailLink\n{\n\ttop: 1px !important;\n}\n\n#CoinsLink\n{\n\ttop: 0;\n}\n\n#CoinsLink img\n{\n\tvertical-align: unset !important;\n}\n\n',
		subTabsHiddenCss = '#sTCBr, #subTabsContainer\n{\n\tdisplay: none;\n}\n\n',
		MainSiteFooterCss = '#MainSiteFooter\n{\n\theight: unset;\n}\n\n#MainSiteFooter div\n{\n\tpadding-bottom: 7px;\n}\n\n',
		FixMuliCss = '.GameRow:hover\n{\n\tcursor: pointer;\n\tbackground-image: unset;\n\tbackground-color: #323232;\n}\n\ntable.dataTable[id *= "GamesTable"] thead\n{\n\theight: 100%;\n}\n\n\t.SideColumn\n{\n\tpadding: 0 !important;\n}\n\n\t.followMeBar\n{\n\tborder-width: 0 !important;\n}\n\n\t.showGames table\n{\n\tborder: 0 !important;\n}\n\n\t.editor\n{\n\tborder-radius: 5px;\n}';

	//main
	styles[0].className = 'Dan_Style';
	styles[0].id = 'Main_Style';
	styles[0].innerHTML = '/*Dan Main Style*/\n\n' + regionCss + tableRegionTrCss + tableRegionTrHighlightedCss + uiTabsPanelTableCss + uiTabsPanelTableTdCss + tableDataTableCss + tableDataTableTheadCss + tableDataTableTheadTrTdChildrenCss + tableDataTableTheadTrTdFirstChildCss + tableDataTableTheadTrTdLastChildCss + tableDataTableTrCss + tableDataTableSpanCss + tableDataTableSpanSpanCss + tableDataTableTdCss + tdDataTableTitleRowCss + MainSiteContentTableFirstOfTypeCss + MainSiteContentDivCss + MainSiteContentTableTrTdCss/* + LivestreamContainerCss*/ + TopRightBarCorrectionsCss + subTabsHiddenCss + MainSiteFooterCss + FixMuliCss;

	//center forum posts

	if (subForum !== null || allForum !== null)
	{
		styles[0].innerHTML += regionTdCss;
	}

	//half the hidden threads row is a different color bug fix
	var htr = document.getElementById('HiddenThreadsRow'),
		tds =
		[
			document.createElement('td'),
			document.createElement('td'),
			document.createElement('td')
		],
		tdNo = 0;

	if (htr === null)
	{
		//if hidden threads row isn't found, don't create the extra td elements
		document.head.appendChild(styles[0]);
	}
	else
	{
		//otherwise create them
		if (allForum !== null)
		{
			while (tdNo < tds.length)
			{
				htr.appendChild(tds[tdNo]);
				tdNo++;
			}
		}

		else if (subForum !== null)
		{
			while (tdNo < tds.length-1)
			{
				htr.appendChild(tds[tdNo]);
				tdNo++;
			}
		}
		
		document.head.appendChild(styles[0]);
	}

//	prevent overflowing forum posts
//	-20 from MainSiteContent padding
//	-6 from .region td padding
//	-14 because of scrollbar width
//	-22 to prevent textarea overflowing

	var tableRegion = document.getElementsByClassName("region"),
		tableRegionNo = 0;

	if (postPage !== null)
	{
		styles[1].innerHTML = '/*Dan Prevent Overflowing Forum Posts Style*/\n\n';

		while (tableRegionNo < tableRegion.length)
		{
			//post for display fix
			if (tableRegion[tableRegionNo].children[0].children[1].children[1].children[0].id.includes("PostForDisplay"))
			{
				styles[1].innerHTML += '#MainSiteContent div#'+tableRegion[tableRegionNo].children[0].children[1].children[1].children[0].id+'\n{\n\tmax-width: '+(screen.width-20-6-14-22)+'px !important;\n}\n\n';
			}

			//post for edit fix
			if (tableRegion[tableRegionNo].children[0].children[1].children[1].children[1] !== undefined)
			{
				if (tableRegion[tableRegionNo].children[0].children[1].children[1].children[1].id.includes("PostForEdit"))
				{
					styles[1].innerHTML += '#MainSiteContent div#'+tableRegion[tableRegionNo].children[0].children[1].children[1].children[1].id+'\n{\n\tmax-width: '+(screen.width-20-6-14-22)+'px !important;\n}\n\n';
				}

				if (tableRegion[tableRegionNo].children[0].children[1].children[1].children[1].children[0].id.includes("TextArea"))
				{
					styles[1].innerHTML += 'textarea#'+tableRegion[tableRegionNo].children[0].children[1].children[1].children[1].children[0].id+'\n{\n\tmax-width: '+(screen.width-20-6-14-22)+'px !important;\n}\n\n';
				}
			}
			tableRegionNo++;
		}

		//prevent images from overflowing
		styles[1].innerHTML += 'div[id *= "PostForDisplay_"] img, div[id *= "PreviewDiv_"] img\n{\n\tmax-width: 100%;\n}';

		styles[1].className = "Dan_Style";
		styles[1].id = "Prevent_Overflowing_Forum_Posts_Style";
		document.head.appendChild(styles[1]);
	}
}

function responsiveCss()
{
	var div = document.getElementsByTagName("div");
	div[0].id = "header";
	div[1].id = "tabsContainer";
	div[2].id = "tabSp";
	div[3].id = "tabMp";
	div[4].id = "tabCoins";
	div[5].id = "tabCommunity";
	div[6].id = "tabSettings";
	div[7].id = "tabHelp";
	//div[8] id is LivestreamContainer

	var isStreaming = false;

	//if no livestream, use div[10], otherwise, use div[12], if its not a flashpage
	if (div[12].id == "MainSiteContent")
	{
		div[10].id = "logo";
		console.log("there isn't a livestream");
	}

	else
	{
		if (flashPage !== null)
		{
			console.log("is flashpage");
			if (div[16].id == "MainSiteContent")
			{
				div[14].id = "logo";
				isStreaming = true;
				console.log("there is a livestream");
			}
			else
			{
				div[12].id = "logo";
			}
		}
		else
		{
			div[12].id = "logo";
			isStreaming = true;
			console.log("there is a livestream");
		}
	}

	//fix absolute positioning
	var header = document.getElementById("header"),
		tabsContainer = document.getElementById("tabsContainer"),
		tabSp = document.getElementById("tabSp"),
		tabMp = document.getElementById("tabMp"),
		tabCoins = document.getElementById("tabCoins"),
		tabCommunity = document.getElementById("tabCommunity"),
		tabSettings = document.getElementById("tabSettings"),
		tabHelp = document.getElementById("tabHelp"),
		LivestreamContainer = document.getElementById("LivestreamContainer"),
		logo = document.getElementById("logo"),
		TopRightBar = document.getElementsByClassName("TopRightBar")[0];

	var tabSpCss = '#tabSp\n{\n\tfloat: left;\n\tmargin-left: 23px;\n}\n\n',
		tabMostCss = '#tabMp, #tabCoins, #tabCommunity, #tabSettings, #tabHelp\n{\n\tfloat: left;\n\tmargin-left: 16px;\n}\n\n',
		LivestreamContainerCss = '#LivestreamContainer\n{\n\tposition: unset;\n\tfloat: left;\n\tmargin-left: 6px;\n}\n\n',
		logoCss = '#logo\n{\n\tposition: unset;\n\tfloat: left;\n\tmargin-left: 8px;\n}\n\n';

	var	SubTabRow = document.getElementById("SubTabRow"),
		subTabsTable;

	if (SubTabRow !== null)
	{
		document.getElementsByTagName("table")[0].id = "subTabsTable";
		subTabsTable = document.getElementById("subTabsTable");
	}

	var subTabsTableCss = '#subTabsTable\n{\n\tfloat: left;\n\tmargin-top: 8px;\n\tmargin-left: 35px;\n}\n\n',
		subTabsTableTdTenWidthCss = '.tdTenWidth\n{\n\twidth: 5px;\n}\n\n',
		TopRightBarCss = '.TopRightBar\n{/*\n\tposition: unset;\n\tfloat: right;\n\tmargin-right: 5px;\n*/}\n\n',
		minWidth1077Css = '@media screen and (min-width: 1077px)\n{\n\t/*1077 - force increase spacing*/\n\t.tdTenWidth\n\t{\n\t\tmin-width: 10px;\n\t\twidth: unset;\n\t}\n}\n\n',
		headerMaxWidth1076Css = '@media screen and (max-width: 1076px)\n{\n\t/*1076 - prevent TopRightBar going in random places*/\n\t#tabMp, #tabCoins, #tabCommunity, #tabSettings, #tabHelp\n\t{\n\t\tmargin-left: 11px;\n\t}\n}\n\n',
		headerMaxWidth1051Css = '@media screen and (max-width: 1051px)\n{\n\t/*1051 - prevent TopRightBar going in random places*/\n\t#tabMp, #tabCoins, #tabCommunity, #tabSettings, #tabHelp\n\t{\n\t\tmargin-left: 6px;\n\t}\n}\n\n',
		headerMaxWidth1047Css = '@media screen and (max-width: 1047px)\n{\n\t/*1047 - make .tdTenWidth hidden*/\n\t.tdTenWidth\n\t{\n\t\tdisplay: none;\n\t\tmin-width: 0;\n\t}\n\n\t#subTabsTable\n\t{\n\t\tmargin-left: 30px;\n\t}\n}\n\n',
		headerMaxWidth1026Css = '@media screen and (max-width: 1026px)\n{\n\t/*1026 - prevent TopRightBar going in random places*/\n\t#tabSp\n\t{\n\t\tmargin-left: 4px;\n\t}\n}\n\n',
		headerMaxWidth1012Css = '@media screen and (max-width: 1012px)\n{\n\t#subTabsTable\n\t{\n\t\tmargin-left: 25px;\n\t}\n}\n\n',
		headerMaxWidth1007Css = '@media screen and (max-width: 1007px)\n{\n\t/*1007 - minimum amount of space and prevent TopRightBar going in random places*/\n\t#tabSp\n\t{\n\t\tmargin-left: 3px;\n\t}\n\n\t#tabMp, #tabCoins, #tabCommunity, #tabSettings, #tabHelp, #LivestreamContainer\n\t{\n\t\tmargin-left: 5px;\n\t}\n\n\t#subTabsTable\n\t{\n\t\tmargin-left: 3px;\n\t}\n}\n\n',
		headerMaxWidth1000Css = '@media screen and (max-width: 1000px)\n{\n\t/*1000 - reduce TopRightBar space*/\n\t.TopRightBar\n\t{\n\t\tright: 1px;\n}\n}\n\n',
		headerMaxWidth989Css = '@media screen and (max-width: 989px)\n{\n\t/*989 - fix LivestreamContainer margin*/\n\t#LivestreamContainer\n\t{\n\tfloat: right;\n\t\tmargin-right: 1px;\n\t}\n}\n\n',
		headerMaxWidth980Css = '@media screen and (max-width: 980px)\n{\n\t#header\n\t{\n\t\tmin-height: 88px !important;\n\t}\n\n\t#LivestreamContainer\n\t{\n\t\tmargin: 50px 165px 0 -165px;\n\t}\n\n\t.TopRightBar\n\t{\n\t\tposition: unset;\n\t\tfloat: right;\n\t\t/*margin-right: -130px;*/\n\t}\n}\n\n',
		headerMaxWidth970Css = '@media screen and (max-width: 970px)\n{\n\t#LivestreamContainer\n\t{\n\t\tmargin-top: 19px;\n\t}\n}\n\n',
		headerMaxWidth963Css = '@media screen and (max-width: 963px)\n{\n\t#subTabsTable\n\t{\n\t\tfloat: left;\n\t\tpadding: unset;\n\t\tmargin-left: 220px;\n\t\tmargin-top: -15px;\n\t}\n\n\t.TopRightBar\n\t{\n\t\tmargin-right: 1px;\n\t}\n}\n\n',
		headerMaxWidth840Css = '@media screen and (max-width: 840px)\n{\n\t/*840 - help tab moves to a new line*/\n\t#SinglePlayerMulitiPlayerCoinsContainer, #CommunitySettingsHelpContainer\n\t{\n\t\tfloat: left;\n\t}\n\n\t#tabCommunity\n\t{\n\t\tmargin-left: 5px;\n\t}\n\n\t#tabSettings, #tabHelp\n\t{\n\t\tmargin-left: 40px;\n\n\t}\n\n\t#LivestreamContainer\n\t{\n\t\tposition: unset;\n\t\tmargin: 2px 1px 0 5px;\n\t}\n\n\t#subTabsTable\n\t{\n\t\tmargin-top: 6px;\n\t\tmargin-left: unset;\n\t}\n\n\t.TopRightBar\n\t{\n\t\tmargin: -52px 1px 0 -40px;\n\t}\n}\n\n',
		headerMaxWidth738Css = '@media screen and (max-width: 738px)\n{\n\t/*738 - move where TopRightBar and LivestreamContainer is located*/\n\n\t#header\n\t{\n\t\tmin-height: 115px !important;\n\t}\n\n\t#LivestreamContainer\n\t{\n\t\tmargin-top: 15px;\n\t\tmargin-right: 165px;\n\t\t}\n\n\t#subTabsTable\n\t{\n\t\tmargin-top: -35px;\n\t}\n\n\t.TopRightBar\n\t{\n\t\tmargin: -15px 1px 0 1px;\n\t}\n}\n\n',
		headerMaxWidth570Css = '@media screen and (max-width: 570px)\n{\n\t#header\n\t{\n\t\tmin-height: 167px !important;\n\t}\n\n\t#subTabsTable\n\t{\n\t\tmargin-top: -37px;\n\t}\n}\n\n',
		headerMaxWidth355Css = '@media screen and (max-width: 355px)\n{\n\t/*355 - header left align*/\n\t#header\n\t{\n\t\tmin-height: 430px !important;\n\t}\n\n\t#tabsContainer\n\t{\n\t\tmax-width: unset;\n\t\twidth: 215px;\n\t}\n\n\t#tabsContainer *\n\t{\n\t\tmargin-bottom: 2px;\n\t}\n\n\t#logo\n\t{\n\t\tfloat: unset;\n\t\twidth: 207px;\n\t}\n\n\t#tabSp\n\t{\n\t\tmargin: 30px 0 0 8px;\n\t\tfloat: unset;\n\t\twidth: 207px;\n\t}\n\n\t#tabMp, #tabCoins, #tabCommunity, #tabSettings, #tabHelp\n\t{\n\t\tfloat: unset;\n\t\tmargin-left: 8px;\n\t\twidth: 207px;\n\t}\n\n\t#LivestreamContainer\n\t{\n\t\tposition: unset;\n\t\tfloat: unset;\n\t\tmargin-left: 8px;\n\t\twidth: 207px;\n\t}\n\n\ttable#subTabsTable\n\t{\n\t\tdisplay: none;\n\t}\n\n\t#sTCBr\n\t{\n\t\tdisplay: unset;\n\t}\n\n\t#subTabsContainer\n\t{\n\t\tposition: unset !important;\n\t\tdisplay: unset;\n\t\tfloat: left;\n\t}\n\n\t#subTabsContainer #SubTabRow div\n\t{\n\t\tfloat: left;\n\t}\n\n\t.divTenWidth\n\t{\n\t\tdisplay: none !important;\n\t}\n\n\t#TopRightBarContainer\n\t{\n\t\twidth: 225px;\n\t}\n\n\t.TopRightBar\n\t{\n\t\tfloat: right;\n\t\tposition: unset;\n\t\tmargin: 0 10px 0 0;\n\t}\n}\n\n';

	//repositioning the logo
	tabsContainer.insertBefore(logo, tabsContainer.children[0]);

	//creates CommunitySettingsHelpContainer
	var SinglePlayerMulitiPlayerCoinsContainer = document.createElement("div");

	SinglePlayerMulitiPlayerCoinsContainer.id = "SinglePlayerMulitiPlayerCoinsContainer";
	SinglePlayerMulitiPlayerCoinsContainer.innerHTML = "<div id = 'tabSp'>" + tabSp.innerHTML + "</div><div id = 'tabMp'>" + tabMp.innerHTML + "</div><div id = 'tabCoins'>"+ tabCoins.innerHTML + "</div>";
	tabsContainer.appendChild(SinglePlayerMulitiPlayerCoinsContainer);
	tabsContainer.insertBefore(SinglePlayerMulitiPlayerCoinsContainer, tabsContainer.children[1]);
	tabSp.remove();
	tabMp.remove();
	tabCoins.remove();

	//creates CommunitySettingsHelpContainer
	var CommunitySettingsHelpContainer = document.createElement("div");

	CommunitySettingsHelpContainer.id = "CommunitySettingsHelpContainer";
	CommunitySettingsHelpContainer.innerHTML = "<div id = 'tabCommunity'>" + tabCommunity.innerHTML + "</div><div id = 'tabSettings'>" + tabSettings.innerHTML + "</div><div id = 'tabHelp'>"+ tabHelp.innerHTML + "</div>";
	tabsContainer.appendChild(CommunitySettingsHelpContainer);
	tabsContainer.insertBefore(CommunitySettingsHelpContainer, tabsContainer.children[2]);
	tabCommunity.remove();
	tabSettings.remove();
	tabHelp.remove();

	//gives td with a html width of 10 a class and removes the html width
	var SubTabRowChildrenNo = 0;

	if (SubTabRow !== null)
	{
		while (SubTabRowChildrenNo < SubTabRow.children.length)
		{
			if (SubTabRow.children[SubTabRowChildrenNo].tagName.match(/td/i) && SubTabRow.children[SubTabRowChildrenNo].width == "10")
			{
				SubTabRow.children[SubTabRowChildrenNo].className = "tdTenWidth";
				SubTabRow.children[SubTabRowChildrenNo].removeAttribute("width");
			}
			SubTabRowChildrenNo++;
		}
	}

//	adds br with line-height of 242px to make subTabsContainer display in the correct place
//	var sTCBr = document.createElement("br");
//
//	sTCBr.id = "sTCBr";
//	sTCBr.style.lineHeight = "242px";
//	header.appendChild(sTCBr);
//	header.insertBefore(sTCBr, header.children[header.children.length-2]);

	//gives subTabs a div structure
	var subTabsContainer = document.createElement("div");

	subTabsContainer.id = "subTabsContainer";
	header.appendChild(subTabsContainer);
	header.insertBefore(subTabsContainer, header.children[header.children.length-2]);

	var subTabsRowDiv = document.createElement("div");

	subTabsRowDiv.id = "SubTabRow";
	subTabsContainer.appendChild(subTabsRowDiv);
	subTabsContainer.insertBefore(subTabsRowDiv, subTabsContainer.children[0]);

	var loopNo = 1,
		br = "",
		brs = [],
		newDivA = "",
		newDivAs = [],
		newDivB = "",
		newDivBs = [],
		newDivC = "",
		newDivCs = [],
		newDivsNo = 0;

	if (SubTabRow !== null)
	{
		while (loopNo < document.getElementsByClassName("SubTabCell").length+2)
		{
			br = document.createElement("br");
			br.style.lineHeight = "19px";
			br.id = "br_"+(loopNo-1);
			brs.push(br);
			newDivA = document.createElement("div");
			newDivA.id = "newDivA_"+(loopNo-1);
			//newDivA.className = "valign=top";
			newDivAs.push(newDivA);
			newDivB = document.createElement("div");
			newDivB.id = "newDivB_"+(loopNo-1);
			//newDivB.className = "SubTabCell";
			newDivBs.push(newDivB);
			newDivC = document.createElement("div");
			newDivC.id = "newDivC_"+(loopNo-1);
			//newDivC.className = "valign=top";
			newDivCs.push(newDivC);
			console.log(loopNo);
			loopNo++;
		}
		console.log("no of subTabs = " + (loopNo-1));
	}

	var STRCNo = -1;

	if (SubTabRow !== null)
	{
		while (newDivsNo < newDivAs.length)
		{
			STRCNo++;
			if (SubTabRow.children[STRCNo] !== undefined)
			{
				newDivAs[newDivsNo].innerHTML = SubTabRow.children[STRCNo].innerHTML;
				subTabsRowDiv.appendChild(newDivAs[newDivsNo]);
				STRCNo++;
				newDivBs[newDivsNo].className = SubTabRow.children[STRCNo].className;
				newDivBs[newDivsNo].innerHTML = SubTabRow.children[STRCNo].innerHTML;
				subTabsRowDiv.appendChild(newDivBs[newDivsNo]);
				STRCNo++;
				newDivCs[newDivsNo].innerHTML = SubTabRow.children[STRCNo].innerHTML;
				subTabsRowDiv.appendChild(newDivCs[newDivsNo]);
				STRCNo++;
				subTabsRowDiv.appendChild(brs[newDivsNo]);
			}
			newDivsNo++;
		}
	}

	//creates TopRightBarContainer
	var TopRightBarContainer = document.createElement("div");

	TopRightBarContainer.id = "TopRightBarContainer";
	header.appendChild(TopRightBarContainer);
	TopRightBarContainer.insertBefore(TopRightBar, TopRightBarContainer.childNodes[0]);

	//overwrites current style
	header.style.minHeight = header.style.height;
	header.style.height = "unset";
	//^ on smaller displays, the links become clickable because of this and doesn't make the background images vanish
	tabSp.removeAttribute("style");
	tabMp.removeAttribute("style");
	tabCoins.removeAttribute("style");
	tabCommunity.removeAttribute("style");
	tabSettings.removeAttribute("style");
	tabHelp.removeAttribute("style");
	logo.removeAttribute("style");
	if (LivestreamContainer !== null)
	{
		LivestreamContainer.removeAttribute("style");
	}
	if (SubTabRow !== null)
	{
		subTabsTable.removeAttribute("style");
		//loopNo is the number of subtabs and 19 is the line-hight of the subtabs
		subTabsContainer.style.height = (loopNo)*19+"px";
		//^ allows the last subtab link to be clickable on smaller displays
	}

	var size,
		normalSize = ((6*31)+(loopNo*19)+61),
		streamingSize = (normalSize+29);

	if (isStreaming)
	{
		size = streamingSize;
	}

	else
	{
		size = normalSize;
	}

	var headerMaxWidth355CssForTopRightBar = '@media screen and (max-width: 355px)\n{\n\t.TopRightBar\n\t{\n\t\tmargin: -'+size+'px 0 0 0;/*tabs height + subTabsContainer height + space*/\n\t}\n}';

	styles[2].className = "";
	styles[2].id = "Responsive_Style";
	styles[2].innerHTML = '/*Dan Responsive Style*/\n\n' + tabSpCss + tabMostCss + LivestreamContainerCss + logoCss + subTabsTableCss + subTabsTableTdTenWidthCss + TopRightBarCss + minWidth1077Css + headerMaxWidth1076Css + headerMaxWidth1051Css + headerMaxWidth1047Css + headerMaxWidth1026Css + headerMaxWidth1012Css + headerMaxWidth1007Css + headerMaxWidth1000Css + headerMaxWidth989Css + headerMaxWidth980Css + headerMaxWidth970Css + headerMaxWidth963Css + headerMaxWidth840Css + headerMaxWidth738Css + headerMaxWidth570Css + headerMaxWidth355Css + headerMaxWidth355CssForTopRightBar;
	document.head.appendChild(styles[2]);
}

//execute the styles
var	wiki = location.href.match(/^https:\/\/www.\warlight\.net\/wiki/i),
	blog = location.href.match(/^https:\/\/www.\warlight\.net\/blog/i);

//is buggy on wiki and blog so prevent the styles from taking effect

if (wiki === null)
{
	if (blog === null)
	{
		mainCss();
		//responsiveCss();//this is a bit buggy on some pages (doesn't look right on postPages)
	}
}