User:Evad37/Custom GeoHack replacement.js
Appearance
From Wikipedia, the free encyclopedia
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.
This code will be executed when previewing this page.
This user script seems to have a documentation page at User:Evad37/Custom GeoHack replacement.
/* Use your own custom page instead of the regular GeoHack. * * It support the following replacement variables found in GeoHack: * {latdegdec} {londegdec} {scale} {span} {osmzoom} * * Based on a script by [[User:Dispenser]]: [[mw:GeoHack/Replacement_script]] * * Instructions: * 1) Add the following line to your common.js (or skin-specific js): * importScript('User:Evad37/Custom_GeoHack_replacement.js'); // [[User:Evad37/Custom_GeoHack_replacement.js]] * * 2) Create your custom GeoHack user subpage at [[User:YOURUSERNAME/GeoHack]] * - use whatever content and formatting you like * - use the replacement variables above in external links, e.g. for Google Maps use * http://maps.google.com/maps?ll={latdegdec},{londegdec}&spn={span},{span}&q={latdegdec},{londegdec} * - more urls can be found at [[Template:GeoTemplate]] * - see [[User:Evad37/GeoHack]] for an example page * * 3) Now coordinates will link to this page instead of GeoHack (specifying real values to take the place of * the replacement variables in external links) * */ jQuery(function($){ if(mw.config.get("wgPageName")!=="User:"+mw.config.get("wgUserName")+"/GeoHack"){ vargeohack_base="//geohack.toolforge.org/geohack.php"; varcoord_filter=/¶ms=([\d.+-]+)_([\d.+-]*)_?([\d.+-]*)_?([NSZ])_([\d.+-]+)_([\d.+-]*)_?([\d.+-]*)_?([EOW])([^&=]*)/; varlink,lat,lon,scale; $("a[href*='"+geohack_base+"']").each(function(){ if(coord_filter.exec($(this).attr("href"))){ // latitude and longitude lat=(1.0*RegExp.1ドル)+((RegExp.2ドル||0)/60.0)+((RegExp.3ドル||0)/3600.0); if(RegExp.4ドル!='N')lat*=-1; lon=(1.0*RegExp.5ドル)+((RegExp.6ドル||0)/60.0)+((RegExp.7ドル||0)/3600.0); if(RegExp.8ドル=='W')lon*=-1; // Determine scale/zoom varparams=RegExp.9ドル; if(/_globe:(?!earth|_|$)/i.test(params))return; if(/_type:(adm3rd|city|mountain|isle|river|waterbody)/.test(params))scale=100000; elseif(/_type:(event|forest|glacier)/.test(params))scale=50000; elseif(/_type:(airport|edu|pass|landmark|railwaystation)/.test(params))scale=10000; elsescale=300000; if(/_dim:([\d.+-]+)(km)?m?/.exec(params))scale=RegExp.1ドル*(RegExp.2ドル?10000:10); if(/_scale:(\d+)(_|$)/.exec(params))scale=RegExp.1ドル; varosmzoom=18-Math.round(Math.log(scale/1693)/Math.log(2)); varzoom=Math.log(1.5e8/scale)/Math.log(2); $(this).attr("href","").attr("onclick","window.open(\"https://en.wikipedia.org/wiki/User:Evad37/GeoHack?lat="+lat+"&lon="+lon+"&scale="+scale+"&span="+span+"&osmzoom="+osmzoom+"&zoom="+zoom+"\")"); } }); }elseif(mw.util.getParamValue('lat')){ varlat=mw.util.getParamValue('lat'); varlon=mw.util.getParamValue('lon'); varscale=mw.util.getParamValue('scale'); varspan=mw.util.getParamValue('span'); varosmzoom=mw.util.getParamValue('osmzoom'); varzoom=mw.util.getParamValue('zoom'); $("a.external").each(function(){ varold_url=$(this).attr("href"); varreplacement_url=old_url.replace(/\{latdegdec\}/g,lat).replace(/\{londegdec\}/g,lon).replace(/\{scale\}/g,scale).replace(/\{span\}/g,scale/1e6).replace(/\{osmzoom\}/g,osmzoom).replace(/\{zoom\}/g,zoom); $(this).attr("href",replacement_url); }); $("#siteSub").append("<hr><img src='https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Symbol_confirmed.svg/16px-Symbol_confirmed.svg.png'/> Coordinates loaded<hr>"); }else{ $("#siteSub").append("<hr><img src='https://upload.wikimedia.org/wikipedia/commons/thumb/1/1d/Information_icon4.svg/20px-Information_icon4.svg.png'/> <span style='font-weight:bold;'>Note:</span> No coordinates loaded (mapping service links will not work)<hr>"); } });