Benutzer:Herzi Pinki/GeoDECpopup.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
 // popup for geohack
 (function(mw,$){
 "use strict";
 vargeohackRE=/https:\/\/geohack\.toolforge\.org\/geohack\.php\?.*params=([\d\.\-]+)_(N|S)_([\d\.\-]+)_(O|E|W).*/;
 // does not work for Wikidata
 // wikidata https://geohack.toolforge.org/geohack.php?params=48.17586_N_16.2918_E_globe:earth&language=de
 // <a href="https://geohack.toolforge.org/geohack.php?params=48.17586_N_16.2918_E_globe:earth&amp;language=de" class="external">48°10'33"N, 16°17'30"E</a>
 // the structure of geohack links

 // <tr class="exif-gpslatitude"><th>Geografische Breite</th><td>47° 28′ 31,59′′ N</td></tr>
 varexifRE=/(\d+)° (\d+)′ ([\d,\.]+)′′ (O|E|W|S|N)/;

 // helper for setTimeout
 functionautoFadeOutPopup(o){
 o.fadeOut("slow");
 }

 functionfadeInPopup(event){
 vardiv=$(event.target).find('.DECpu');
 div.fadeIn("slow");
 setTimeout(autoFadeOutPopup,7000,div);
 returnfalse;
 }

 functionfadeOutPopup(event){
 varsel=document.getSelection().toString();
 if(!sel){// only of no selection for copy
 $(event.target).closest('.DECpu').fadeOut("slow");
 }
 returnfalse;
 }

 $(document).ready(function(){
 vartexts=(functiontexts(){
 vartranslations={
 en:{
 copy:"copy to clipboard",
 logoTitle:"Geotools by Herzi Pinki",
 credits:" DEC-Coords:",
 },
 de:{
 copy:"In die Zwischenablage kopieren",
 logoTitle:"Geowerkzeuge von Herzi Pinki",
 credits:" DEC-Koordinaten:",
 },
 },
 chain=mw.language.getFallbackLanguageChain(),
 len=chain.length,
 ret={},
 i=len-1;

 while(i>=0){
 if(translations.hasOwnProperty(chain[i])){
 $.extend(ret,translations[chain[i]]);
 }
 i-=1;
 }
 returnret;
 }());

 functionaddPopup(parentNode,cval,id,widthFac=1){
 vardynDiv=document.createElement("div");
 dynDiv.setAttribute("id",id);

 varheader=document.createElement("div");
 header.style.fontSize="small";
 header.style.whiteSpace="nowrap";

 // copy to clipboard
 varcopybutton=document.createElement("img");
 copybutton.style.width="30px";
 copybutton.style.height="30px";
 copybutton.style.float="right";
 copybutton.style.padding="5px 1px";
 copybutton.src="//upload.wikimedia.org/wikipedia/commons/thumb/a/a2/Edit-copy.svg/30px-Edit-copy.svg.png";
 copybutton.title=texts.copy;
 copybutton.decoding="async";
 header.appendChild(copybutton);

 varlogo=document.createElement("img");
 logo.style.width="15px";
 logo.style.height="15px";
 logo.src="//upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Erioll_world.svg/15px-Erioll_world.svg.png";
 logo.title=texts.logoTitle;
 logo.decoding="async";
 header.appendChild(logo);
 header.appendChild(document.createTextNode(texts.credits));
 dynDiv.appendChild(header);

 varcvalNode=document.createElement("div");
 cvalNode.appendChild(document.createTextNode(cval));
 cvalNode.className="DECpuCval";
 cvalNode.style.clear="left";
 cvalNode.style.lineHeight=1.5;
 //cvalNode.style.textAlign = "center";
 cvalNode.style.padding="4px 0px";
 cvalNode.style.whiteSpace="nowrap";

 dynDiv.appendChild(cvalNode);

 dynDiv.className="DECpu";
 dynDiv.style.position="absolute";
 dynDiv.style.width=(180*widthFac).toString+'px';
 dynDiv.style.border="1px solid";
 dynDiv.style.background="#ddd";
 dynDiv.style.padding="2px 5px";
 dynDiv.style.display="none";
 dynDiv.style.left="20px";
 dynDiv.style.top="20px";
 dynDiv.style.textAlign="left";
 dynDiv.style.zIndex="200";

 // need intermediate parent for positioning
 varrelParent=document.createElement("div");
 relParent.style.position="relative";
 //relParent.style.width = "210px";
 relParent.style.width="0";
 relParent.style.height="0";
 relParent.style.display="inline";

 relParent.append(dynDiv);
 parentNode.prepend(relParent);
 varrectDiv=relParent.getBoundingClientRect();
 varbodyDiv=$("body")[0].getBoundingClientRect();
 if(rectDiv.left+rectDiv.width+210>bodyDiv.right){
 dynDiv.style.left=(parseInt(dynDiv.style.left,10)-(210-(Math.round(bodyDiv.right-rectDiv.right))))+"px";
 }

 parentNode.addEventListener("mouseenter",fadeInPopup);

 dynDiv.addEventListener("click",fadeOutPopup);

 // putting the function to outer scope creates an exception
 // uncaught (in promise) DOMException: clipboard write was blocked due to lack of user activation.
 copybutton.addEventListener("click",function(event){
 varnodes=$(event.target).closest('.DECpu').find('.DECpuCval');
 if(nodes){
 navigator.clipboard.writeText(nodes[0].childNodes[0].nodeValue);
 }
 returnfalse;
 });
 }

 varanchors=document.getElementsByTagName("a");
 vari;// declare i
 for(i=0;i<anchors.length;i++){
 varcoords=anchors[i].href.match(geohackRE);
 if(coords){
 varparentNode=anchors[i].parentNode;
 // geohack link found
 // coords[0] is the whole line
 // var geohackRE = /https:\/\/geohack\.toolforge\.org\/geohack\.php\?.*params=([\d\.\-]+)_(N|S)_([\d\.\-]+)_(O|E|W).*/;
 // (1 ) (2 ) (3 ) (4 ) 
 varlat=(coords[2]=='S')?-coords[1]:coords[1];
 varlon=(coords[4]=='W')?-coords[3]:coords[3];
 lat=Math.round(lat*1000000)/1000000;// round to 6 digits
 lon=Math.round(lon*1000000)/1000000;

 varcval=lat.toString()+', '+lon.toString();

 varid="DEC"+i.toString();
 addPopup(parentNode,cval,id);

 }
 }

 // <tr class="exif-gpslatitude"><th>Geografische Breite</th><td>47° 28′ 31,59′′ N</td></tr>
 varlatNodes=document.getElementsByClassName("exif-gpslatitude");
 varlatNode=null;
 if(latNodes.length>0){
 latNode=latNodes[0];
 }

 varlongNodes=document.getElementsByClassName("exif-gpslongitude");
 varlongNode=null;
 if(longNodes.length>0){
 longNode=longNodes[0];
 }

 vardirNodes=document.getElementsByClassName("exif-gpsimgdirection");
 vardirNode=null;
 if(dirNodes.length>0){
 dirNode=dirNodes[0];
 }

 varaltNodes=document.getElementsByClassName("exif-gpsaltitude");
 varaltNode=null;
 if(altNodes.length>0){
 altNode=altNodes[0];
 }

 if(latNode&&longNode){
 varlatVal=latNode.firstChild.nextSibling.firstChild.nodeValue;
 varlongVal=longNode.firstChild.nextSibling.firstChild.nodeValue;
 varhookNode=latNode.firstChild.nextSibling;
 varmsgBoxNode=null;
 varimages=$("table.messagebox img[src*='Gnome-edit-clear.svg']");
 if(images.length>0){
 msgBoxNode=images[0].parentNode.parentNode.parentNode;
 }

 varexifLat;
 varexifLong;

 // <tr class="exif-gpslatitude"><th>Geografische Breite</th><td>47° 28′ 31,59′′ N</td></tr>
 // var exifRE = /(\d+)° (\d+)′ ([\d,\.]+)′′ (O|E|W|S|N)/;
 // (1 ) (2 ) (3 ) (4 )

 varexifCoords=latVal.match(exifRE);
 if(exifCoords){
 exifCoords[3]=exifCoords[3].replace(',','.');// uniform comma, if any
 exifLat=parseInt(exifCoords[1])+parseFloat(exifCoords[2])/60+parseFloat(exifCoords[3])/3600;
 exifLat=(exifCoords[4]=="S")?-exifLat:exifLat;
 exifLat=Math.round(exifLat*1000000)/1000000;// round to 6 digits
 }
 exifCoords=longVal.match(exifRE);
 if(exifCoords){
 exifCoords[3]=exifCoords[3].replace(',','.');// uniform comma, if any
 exifLong=parseInt(exifCoords[1])+parseFloat(exifCoords[2])/60+parseFloat(exifCoords[3])/3600;
 exifLong=(exifCoords[4]=="W")?-exifLong:exifLong;
 exifLong=Math.round(exifLong*1000000)/1000000;// round to 6 digits
 }

 varexifAlt='';
 varexifDir='';
 varaltVal='';
 vardirVal='';
 if(altNode){
 altVal=altNode.firstChild.nextSibling.firstChild.nodeValue;
 // 633,7 Meter über dem Meeresspiegel
 // 1.633,7 Meter über dem Meeresspiegel
 exifAlt=altVal.match(/^([\d,\.]+).*/);
 if(exifAlt){
 exifAlt[1]=exifAlt[1].replace(/\.(\d+,)/,'1ドル');// uniform comma, if any; 1.633,7 case -> 1633,7
 exifAlt[1]=exifAlt[1].replace(/^(\d)\.(\d{3,3})/,'1ドル2ドル');// remove 1000 sep, if any; 1.633 case -> 1633
 exifAlt[1]=exifAlt[1].replace(',','.');// uniform comma, if any
 altVal=parseFloat(exifAlt[1]);
 }
 }
 if(dirNode){
 dirVal=dirNode.firstChild.nextSibling.firstChild.nodeValue;
 // 123,7
 exifDir=dirVal.match(/^([\d,\.]+).*/);
 if(exifDir){
 exifDir[1]=exifDir[1].replace(',','.');// uniform comma, if any
 dirVal=parseFloat(exifDir[1]);
 }
 }


 if(exifLat!=0||exifLong!=0){
 varcval2='{{Location|'+exifLat.toString()+'|'+exifLong.toString();
 // alt:633.7_source:exif_heading:149.25
 varpar='|source:exif';
 if(altVal){
 par+='_alt:'+altVal;
 }
 if(dirVal){
 par+='_heading:'+dirVal;
 }
 cval2+=par+'}}';

 addPopup(hookNode,cval2,"DECexif",3);
 if(msgBoxNode){
 addPopup(msgBoxNode,cval2,"DECmsgExif",3);
 }
 }
 }

 });
 }(window.mediaWiki,window.jQuery));
Abgerufen von „https://de.wikipedia.org/w/index.php?title=Benutzer:Herzi_Pinki/GeoDECpopup.js&oldid=248883204"