// ==UserScript==
// @name           Letzes Dorf
// @description    Zeigt Letztes Dorf auf dem Versammlungsplatz an.
// @version        1.0a (2010-03-03 18:42)
// @author         realneode
// @namespace      a
// @include        http://*.*staemme.*screen=place*
// ==/UserScript==

var tmp;
var server = document.location.host.split('.')[0];
var url = document.location.href;
var t = (url.split("&t=").length>1) ? "_"+url.split("&t=")[1].split("&")[0] : "";
t = (url.split("?t=").length>1) ? "_"+url.split("?t=")[1].split("&")[0] : t;

function $path(text){
	return (document.evaluate(text,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null));
}

function GM_getValue(name, defaultValue) {
	var value = localStorage.getItem("ld_"+name);
	return (!value) ? defaultValue : value;
}

if(document.getElementsByClassName("menu nowrap quickbar")[0]){
	if (document.location.href.match(/try=confirm/)){
		try{
			tmp = $path('id(\'content_value\')/form/table/tbody/tr[2]/td[2]/a').snapshotItem(0).textContent.split("(");
			tmp = tmp[tmp.length-1].split(")")[0];
			localStorage.setItem("ld_"+server+t, tmp);
		}
		catch(e){}
	}

	try{
		tmp = $path('id(\'content_value\')/table/tbody/tr/td/form/table[2]/tbody/tr/td[3]');
		var koords = GM_getValue(server+t, false);
		if (koords){
			koords = koords.split("|");
			var link = "javascript:(function(){document.forms['units'].elements['x'].value='"+koords[0]+"';"
					+ "document.forms['units'].elements['y'].value='"+koords[1]+"';}());";
			tmp.snapshotItem(0).innerHTML+="<a href=\"" + link + "\">&raquo; Letzes Dorf</a><br>";
		}
	}
	catch(e){}
}

