// RetroFrog Run Away Confirmation Script
// 
// ==UserScript==
// @name           Run Away Confirmation Script
// @namespace      http://www.romines.info/kol
// @include        *kingdomofloathing.com/fight.php*
// @include        *127.0.0.1:600*/fight.php*
// @description    Version 0.3
// 
// ==/UserScript==


/********************************** Recent Changes **********************************************
Recent Updates:
	0.1	New script - makes it less easy to hit the run away button accidentally ;-)
		Hint: If you *really* want to hit it, use tab
	0.2	Caught the ability to click on the button if you didn't move your mouse;-)
   	0.3	Prevent the button from running away if you have the ctrl key held down
********************************************************************************************/
GM_setValue("scriptVer","0.3");
GM_setValue("scriptName","RunAwayConfirm");
GM_setValue("scriptURL","http://www.romines.info/kol/runaway_confirmation.user.js");

function conf() {
	var runaway = confirm('Really run away?  I mean, really?');
	if (runaway) {
		var runAwayForm = document.getElementsByName('runaway')[0];
		runAwayForm.submit();
		return true;
	} else {
		return false;
	}
}

var pos = 0;
var runAwayButton;

function move(e) {
	//if they're using the ctrl key, don't move
	if (e.ctrlKey) return;
	if (pos == 0) {
		runAwayButton.style.marginLeft = 200;
		runAwayButton.style.marginRight = 0;
		pos = 1;
	} else {
		runAwayButton.style.marginLeft = 0;
		runAwayButton.style.marginRight = 200;
		pos = 0;
	}
	
}

if (window.location.pathname == "/fight.php") {
	var buttons = document.getElementsByTagName('input');
	for (var i = 0; i < buttons.length; i++) {
		if (buttons[i].value=='Run Away') {
			runAwayButton = buttons[i];
			runAwayButton.addEventListener('click', conf, false);
			runAwayButton.type='button';
			runAwayButton.addEventListener('mouseover', move, false);
			runAwayButton.addEventListener('mousedown', move, true);
			break;
		} 
	}
}

