User:Dschwen/addkmllinks.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Dschwen/addkmllinks. |
var addkmllinks =
{
config:
{
coordurls : new Array (
'http://tools.wikimedia.de/~magnus/geo/geohack.php?',
'http://www8.brinkster.com/erikbaas/wiki/maps.asp?',
'http://www.nsesoftware.nl/wiki/maps.asp?'
)
},
// Check against coordinate urls
isMaplink : function( url )
{
if( typeof(url) != 'string' ) return false;
with(addkmllinks)
{
// for( var key = 0; key < config.coordurls.length; key++ ) {
for( var key in config.coordurls ) {
if( url.substr(0,config.coordurls[key].length) == config.coordurls[key] )
return true;
}
}
return false;
},
install : function()
{
with(addkmllinks)
{
var coordnum = 0;
var len; // cache array length for iterations
var links = document.getElementsByTagName('a');
len = links.length;
for( var key = 0; key < len; key++ )
{
link = links[key];
if( isMaplink(link.href) ) coordnum++;
} //for
if( coordnum > 1 )
{
var content = document.getElementById('content');
var el;
el = document.createElement('a');
el.href = 'http://suda.co.uk/projects/microformats/geo/get-geo.php?type=kml&uri=' + encodeURIComponent( document.location );
el.appendChild( document.createTextNode('Export points of interest') );
content.appendChild(el);
}
} //with
}
}
//
// Hook up installation function
//
addOnloadHook(addkmllinks.install);
//</pre>