// ==UserScript==
// @name          KoL Gift Shop Guy Namer
// @description   Names the gift shop guy
// @namespace     http://www.mrphlip.com/
// @include       http://kingdomofloathing.com/town_giftshop.php*
// @include       http://www*.kingdomofloathing.com/town_giftshop.php*
// ==/UserScript==

names = new Array("Boris", "Richard", "Joshua", "Johnathan", "Horace", "Christopher", "Robin", "Gregory", "Steven", "Lachlan", "Harry", "Timothy", "Harold", "Marvin", "Damien", "David", "Bernard", "Adam", "Henry", "Julian", "Aaron", "Arnold", "Percy", "Charles", "Benjamin", "Ronald");
greetings = new Array("Hi", "Hey", "Hello", "Greetings", "Salutations");
namestarts = new Array("I'm", "my name's", "the name's", "you may call me");
// ok, kind of weird way to find the text node, but meh...
// find the "send someone a package" link
var links = document.getElementsByTagName("a");
var link;
for (var i = 0; i < links.length; i++)
{
	if (links[i].href.indexOf("sendgift") >= 0)
	{
		link = links[i];
		break;
	}
}
if (link)
{
	name = names[Math.floor(Math.random() * names.length)];
	greeting = greetings[Math.floor(Math.random() * greetings.length)];
	namestart = namestarts[Math.floor(Math.random() * namestarts.length)];
	intro = greeting + ", " + namestart + " " + name;
	if (Math.random() < 0.1)
		intro += " (or was it " + names[Math.floor(Math.random() * names.length)] + "?)";
	intro += ". ";
	link.previousSibling.nodeValue = intro + link.previousSibling.nodeValue;
}