// ==UserScript==
// @name           Mall Username
// @namespace      http://cmeister2.co.uk
// @description    Changes chat username click from profile to mall
// @include        http://*kingdomofloathing.com/lchat.php
// ==/UserScript==

function clickhandler(e){
	var target = e.target;
	i=10;
	do{
		if(target.tagName=='A')break;
		target = target.parentNode;
	}while(target && --i)
	if(!i || !target)return;

	var url = target.getAttribute('href');

	switch(e.button){
		case 0:
			if(m=url.match(/showplayer\.php\?who=(\d+)/))
				target.setAttribute('href','mallstore.php?whichstore='+m[1]);
			break;
		case 2:
			if(m=url.match(/mallstore\.php\?whichstore=(\d+)/))
				target.setAttribute('href','showplayer.php?who='+m[1]);
			break;
	}
}
document.addEventListener('click',function(e){
	switch(e.button){
		case 0:
			unsafeWindow.disappear(e);
			clickhandler(e);
			break;
		case 2:
			clickhandler(e);
			break;
	}
},false);