// ==UserScript==
// @name        Script Within Inappropriate Prepositions
// @namespace   http://jusnel.100webspace.net/kol/
// @description Randomizes the prepositions in every page.
// @include     *.kingdomofloathing.com/*
// @include     *127.0.0.1:600*
// @exclude     */login.php*
// @exclude     *forums.kingdomofloathing.com/*
// ==/UserScript==
// Thanks to Phlip and Aprocalypse, whose scripts I, uh,
// "borrowed" from in order to write this. :D


var preps= ["about","above","across","after","against","along",
	"among","around","at","before","behind","below","beneath",
	"beside","between","beyond","by","down","during","except","for",
	"from","in","inside","into","like","near","of","off","on",
	"onto","out","outside","over","past","through","throughout",
	"to","under","until","up","upon","with","within","without"];
var numpreps = preps.length;
var Preps= ["About","Above","Across","After","Against","Along",
	"Among","Around","At","Before","Behind","Below","Beneath",
	"Beside","Between","Beyond","By","Down","During","Except","For",
	"From","In","Inside","Into","Like","Near","Of","Off","On",
	"Onto","Out","Outside","Over","Past","Through","Throughout",
	"To","Under","Until","Up","Upon","With","Within","Without"];
var numPreps = Preps.length;


function replacePrepsInElements(elements)
{
	for (var i = 0; i < elements.length; i++)
	{
		text = elements[i].innerHTML;
		lower = text.toLowerCase();
		if ( (lower.indexOf('<form') > -1) || (lower.indexOf('/form>') > -1) || 
			(lower.indexOf('<input') > -1) || (lower.indexOf('/input>') > -1) )
		{
			continue;
		}

		text = text.replace(/ (about|above|across|after|against|along|among|around|at|before|behind|below|beneath|beside|between|beyond|by|down|during|except|for|from|in|inside|into|like|near|of|off|on|onto|out|outside|over|past|through|throughout|to|under|until|up|upon|with|within|without)(?![a-z])/g,' __SCRIPTWITHIN_LOWER__');

		text = text.replace(/(About|Above|Across|After|Against|Along|Among|Around|At|Before|Behind|Below|Beneath|Beside|Between|Beyond|By|Down|During|Except|For|From|In|Inside|Into|Like|Near|Of|Off|On|Onto|Out|Outside|Over|Past|Through|Throughout|To|Under|Until|Up|Upon|With|Within|Without)(?![a-zA-Z])/g,'__SCRIPTWITHIN_UPPER__');

		text = text.replace(/[Rr]age __SCRIPTWITHIN_(LOWER|UPPER)__ [Tt]he/g,'Rage Against the');

		while ( text.indexOf('__SCRIPTWITHIN_LOWER__') > -1 )
		{
			text = text.replace( '__SCRIPTWITHIN_LOWER__', preps[ Math.floor(Math.random()*numpreps) ] );
		}
		while ( text.indexOf('__SCRIPTWITHIN_UPPER__') > -1 )
		{
			text = text.replace( '__SCRIPTWITHIN_UPPER__', Preps[ Math.floor(Math.random()*numPreps) ] );
		}

		elements[i].innerHTML = text;
	}
}

var tablecells = document.getElementsByTagName('td');
replacePrepsInElements(tablecells);

var paragraphs = document.getElementsByTagName('p');
replacePrepsInElements(paragraphs);

var anchors = document.getElementsByTagName('a');
replacePrepsInElements(anchors);

var blockquotes = document.getElementsByTagName('blockquote');
replacePrepsInElements(blockquotes);

var blockquotes = document.getElementsByTagName('div');
replacePrepsInElements(blockquotes);

var blockquotes = document.getElementsByTagName('span');
replacePrepsInElements(blockquotes);

var forms = document.getElementsByTagName('form');
replacePrepsInElements(forms);
