Urban Dead GPS Coords

By Revenant Last update Mar 9, 2009 — Installed 191 times. Daily Installs: 0, 0, 0, 3, 7, 0, 1, 3, 2, 0, 1, 0, 3, 0, 0, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 2, 3, 2, 1
// ==UserScript==
// @name           Urban Dead GPS Coords
// @namespace      tag:grimrevenant@gmail.com,2009-03-09:UrbanDead:Scripts
// @description    Put the map coordinates on the page
// @include        http://www.urbandead.com/map.cgi*
// ==/UserScript==

// Almost entirely based on Swiers' GPS bookmarklet - http://wiki.urbandead.com/index.php/Bookmarklets#GPS

Xs=document.body.innerHTML.match(/\d\d?(?=-\d\d?" type="hidden">)/g);
Ys=document.body.innerHTML.match(/\d\d?(?=" type="hidden">)/g);
Xsum=0;
Ysum=0;
Xav=0;
Yav=0;

for (i=0;Xs[i];i++) {
	Xs[i]=parseInt(Xs[i]);
	Ys[i]=parseInt(Ys[i]);
	Xsum+=Xs[i];
	Ysum+=Ys[i];
}

Xav=Xsum/Xs.length;
Yav=Ysum/Ys.length;
if (Xav<1) {Xav=1;}
if (Yav<1) {Yav=1;}
if (Xav>99) {Xav=99;}
if (Yav>99) {Yav=99;}
coords=Xav+"-"+Yav;

function showCoords() {
	document.body.innerHTML=document.body.innerHTML.replace(/(class="sb">.+?)</,'$1 ['+[coords]+']<');
}

showCoords();