Jump to content

User:PerfektesChaos/js/idResolver/core/r.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// User:PerfektesChaos/js/idResolver/core/r.js
/// 2018-10-02 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#364CDDD2#
/// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA)
///<nowiki>
(function(mw,$){
"use strict";
var Version=1.92,IDA="idResolver",IDEA={illusive:0.85,signature:"ext.gadget."+IDA,sub:"/core",type:IDA,seen:"#00008B"},CHANCE={},TYPES,OO;
TYPES={pdf:{ext:"PDF",start:"[./=]",commons:"2/23/Icons-mini-file_acrobat.gif"
},msexcel:{ext:"XLS",commons:"b/ba/Page_white_excel.png"
},msword:{ext:"DOC",commons:"a/a1/Page_white_word.png"
}
};
function fair(adjust){
return adjust.replace(/'/g, "&#39;" )
.replace(/</g,"&lt;")
.replace(/>/g,"&gt;");}
function fiat(application,adaption){
IDA=application;
IDA.vsn=IDA.vsn+" /"+Version;
if(typeof IDA.launched!=="boolean"){
IDA.launched=true;
IDEA.cfg=adaption;
if(typeof IDEA.cfg.seen==="string"&&/[0-9A-Fa-f]{6}/.test(IDEA.cfg.seen)){
IDEA.seen="#"+IDEA.cfg.seen;}
mw.loader.using(["oojs","oojs-ui-core","oojs-ui-widgets"],IDEA.first);}}
function find(append,already){
return(already?already+",":"")+"[href*='"+append+"']";}
function fire(){
var signature=IDEA.signature+IDEA.sub,rls;
if(mw.loader.getState(signature)!=="ready"){
rls={};
rls[signature]="ready";
mw.loader.state(rls);
mw.hook(IDEA.type+IDEA.sub+".ready").fire(fiat);}}
CHANCE.dnb={live:true,re:new RegExp("/(?:gnd/)?([0-9][0-9.]+-?[0-9xX])$")
};
CHANCE.dnb.resolver=[
"https://d-nb.info/#","https://www.deutsche-digitale-bibliothek.de/entity/#","http://swb.bsz-bw.de/DB=2.104/SET=1/TTL=1//CMD?retrace=0"+"&trm_old=&ACT=SRCHA&IKT=2999&SRT=RLV&MATCFILTER=N&MATCSET=N"+"&NOABS=Y&SHRTST=50&TRM=#","https://beacon.findbuch.de/seealso/pnd-aks?format=sources&id=#"];
CHANCE.dnb.find=function(){
var s=find("//d-nb.info/");
s=find("//www.deutsche-digitale-bibliothek.de/entity/",s);
IDEA.$external.filter(s).each(CHANCE.dnb.found);
s=find("//portal.dnb.de/opac.htm?method=");
IDEA.$external.filter(s).filter(find("&query=idn%3D")).each(CHANCE.dnb.found2);
};
CHANCE.dnb.found=function(ignore,element){
var $a=$(element),sign=$a.attr("href"),got=CHANCE.dnb.re.exec(sign);
if(got){
IDEA.fiat($a,"dnb",got[1]);}
};
CHANCE.dnb.found2=function(ignore,element){
var $a=$(element),sign=$a.attr("href"),got;
if(typeof CHANCE.dnb.re2!=="object"){
CHANCE.dnb.re2=new RegExp("&query=idn%3D([0-9]+)\\b");}
got=CHANCE.dnb.re2.exec(sign);
if(got){
IDEA.fiat($a,"dnb",got[1]);}
};
CHANCE.doi={live:true,re:new RegExp("[/=](10\\.[0-9]+(?:/|%2F)[^?&#]+)(?:[?&#].*)?$")};
CHANCE.doi.resolver=[
"https://doi.org/#","https://dx.doi.org/#","http://dx.doi.org/#","http://doai.io/#","https://openaccessbutton.org/#","https://sci-hub.io/#","https://scholar.google.de/scholar?q=#"];
CHANCE.doi.find=function(){
var seek=find("//dx.doi.org/10.");
IDEA.$extiw.filter(seek).each(CHANCE.doi.found);
seek=find("//doai.io/10.",seek);
seek=find("//openaccessbutton.org/10.",seek);
IDEA.$external.filter(seek).each(CHANCE.doi.found);
seek=find("//onlinelibrary.wiley.com/");
IDEA.$external.filter(seek).filter(find("doi/10."))
.each(CHANCE.doi.found);
seek=find("//www.springerlink.com/");
IDEA.$external.filter(seek).filter(find("ndex/10."))
.each(CHANCE.doi.found);
seek=find("google.com/scholar?q=");
seek=find("google.de/scholar?q=",seek);
IDEA.$external.filter(seek).filter(find("/scholar?q=10."))
.each(CHANCE.doi.found);
};
CHANCE.doi.found=function(ignore,element){
var $a=$(element),sign=$a.attr("href"),got=CHANCE.doi.re.exec(sign);
if(got){
sign=got[1];
try{
sign=decodeURIComponent(sign);
}catch(e){
}
IDEA.fiat($a,"doi",sign);}
};
CHANCE.isbn={live:true,resolver:null};
CHANCE.isbn.factory=function(alien){
var r,suite;
if(alien){
suite="isbn/"+alien;
}else{
suite="isbn";}
if(typeof IDEA.patterns[suite]==="object"){
r=IDEA.patterns[suite];
}else{
r=IDEA.factory(suite,CHANCE.isbn.lib.finder(alien));}
return r;
};
CHANCE.isbn.fed=function(application){
CHANCE.isbn.lib=application;
CHANCE.isbn.list=false;
if(typeof CHANCE.isbn.cfg==="object"){
if(typeof CHANCE.isbn.cfg.list==="boolean"){
CHANCE.isbn.list=CHANCE.isbn.cfg.list;}
if(typeof CHANCE.isbn.cfg.catalogs==="object"){
CHANCE.isbn.lib.furnish(CHANCE.isbn.cfg.catalogs);}}
CHANCE.isbn.re=new RegExp("/([0-9]+[xX]?)$");
CHANCE.isbn.fire();
};
CHANCE.isbn.feeder=function(after){
var rls;
CHANCE.isbn.fire=after;
if(!mw.loader.getState("ext.gadget.isbnLib")){
rls={};
rls["ext.gadget.isbnLib"]="loading";
mw.loader.state(rls);
mw.loader.load("https://en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/isbnLib/"+(Version>0?"r":"d")+".js&bcache=1&maxage=604810&action=raw&ctype=text/javascript");}
mw.hook("isbnLib.ready").add(CHANCE.isbn.fed);
};
CHANCE.isbn.$fetch=function(ask){
var slang=CHANCE.isbn.lib.focus(ask),pattern=CHANCE.isbn.factory(slang),$a=$("<a>"),$r=$("<span>"),s,$span;
$a.attr({"href":"/wiki/Special:Booksources/"+ask,
"target":IDEA.fork("www","URL"),
"title":s}).css({"font-weight":"bold"})
.text("Wiki");
$r.append($a).append($("<br />"));
IDEA.fill("isbn",pattern,ask,$r);
if(CHANCE.isbn.list){
s=CHANCE.isbn.lib.flip(ask);
if(s){
$span=$("<span>").css({"color":"#404040"}).text(s);
$r.append($("<br />"))
.append($span);}}
return $r;
};
CHANCE.isbn.find=function($area){
$area.find(".mw-magiclink-isbn").each(CHANCE.isbn.found);
};
CHANCE.isbn.found=function(ignore,element){
var $a=$(element),source=$a.attr("href"),got=CHANCE.isbn.re.exec(source),show,sign;
if(got){
sign=got[1].toUpperCase();
show=CHANCE.isbn.lib.format(sign);
if(show){
$a.text("ISBN "+show);
IDEA.fiat($a,"isbn",sign);}}
};
CHANCE.issn={live:true,re:new RegExp("[/=:]([0-9]{4}-?[0-9]{3}[0-9xX])(?:&.+)?$")
};
CHANCE.issn.resolver=[
"http://www.worldcat.org/issn/#","http://dispatch.opac.dnb.de/DB=1.1/CMD?ACT=SRCHA&IKT=8&TRM=#","http://services.dnb.de/fize-service/gvr/html-service.htm?issn=#","http://www.jstor.org/journals/#","http://www.sudoc.abes.fr//DB=2.1/SET=1/TTL=1/CLK?IKT=8&TRM=#"];
CHANCE.issn.find=function(){
var s=find("//www.worldcat.org/issn/");
s=find("//www.worldcat.org/search?fq=x0:jrnl&q=n2:",s);
s=find("//zdb-katalog.de/list.xhtml?key=iss&t=",s);
s=find("//services.dnb.de/fize-service/gvr/html-service.htm?issn=",s);
s=find("//dispatch.opac.d-nb.de/DB=1.1/CMD?ACT=SRCHA&IKT=8&TRM=",s);
IDEA.$external.filter(s).each(CHANCE.issn.found);
};
CHANCE.issn.found=function(ignore,element){
var $a=$(element),sign=$a.attr("href"),got=CHANCE.issn.re.exec(sign),s;
if(got){
s=got[1].replace(/-/,"");
IDEA.fiat($a,"issn",s);}
};
CHANCE.www={live:true};
CHANCE.www.resolver=[
"https://web.archive.org/web/*/#","http://www.webcitation.org/query?url=#","https://archive.is/#"];
CHANCE.www.$fetch=function(ask){
var pattern=IDEA.factory("www",CHANCE.www.resolver),s=fair(ask),$a=$("<a>"),$r=$("<span>");
$a.attr({"href":s,
"target":IDEA.fork("www","URL"),
"title":s}).css({"font-weight":"bold"})
.text("URL");
$r.append($a).append($("<br />"));
IDEA.fill("www",pattern,s,$r);
return $r;
};
CHANCE.www.find=function(){
IDEA.$external.filter(find("//")).each(CHANCE.www.found);
};
CHANCE.www.found=function(ignore,element){
var $a=$(element),sign=$a.attr("href"),s;
if(sign.indexOf(".org/w")>0){
if(typeof CHANCE.www.reWiki!=="object"){
s="(?:ipedia|ibooks|idata|imedia|imediafoundation|inews|iquote|isource|iversity|ivoyage|tionary)";
s="\\/\\/[^/#?]*\\.?wik"+s+"\\.org/w";
s="^(?:[hft]+tps?:)?"+s;
CHANCE.www.reWiki=new RegExp(s);}
if(CHANCE.www.reWiki.test(sign)){
sign=false;}}
if(sign){
IDEA.fiat($a,"www",sign);
IDEA.format($a,sign);}
};
CHANCE.arxiv={live:false};
CHANCE.handle={live:false};
CHANCE.lccn={live:false};
CHANCE.pmid={live:false};
IDEA.factory=function(assign,apply){
var i,r,show,src;
if(typeof IDEA.patterns[assign]==="object"){
r=IDEA.patterns[assign];
}else{
r=[];
for(i=0;i<apply.length;i++){
src=apply[i];
show=IDEA.flat(src);
if(show){
r.push([src,show]);}}
IDEA.patterns[assign]=r;}
return r;
};
IDEA.features=function(adapt){
var i,src,urls;
if(typeof adapt.cfg.resolver==="object"){
urls=adapt.cfg.resolver;
if(typeof urls.length==="number"){
for(i=0;i<urls.length;i++){
src=urls[i];
if($.inArray(src,adapt.resolver)<0){
adapt.resolver.push(src);}}}}
};
IDEA.$fetch=function(assigned,ask,already){
var pattern=IDEA.factory(assigned,CHANCE[assigned].resolver),$r=$("<span>");
IDEA.fill(assigned,pattern,ask,$r,already);
return $r;
};
IDEA.fiat=function($a,assigned,access){
var shift=CHANCE[assigned].shift,props;
if(shift){
$a.attr("href",shift.replace(IDEA.re,access)).addClass("external "+IDEA.type+"-shifted");
}else{
props={
"data-href":$a.attr("href")};
props[IDEA.store+"scope"]=assigned;
props[IDEA.store+"sign"]=access;
if(assigned==="www"){
props.title=access;
}else{
props.title=assigned+":"+access;
$a.css({"white-space":"nowrap"});}
$a.attr(props).addClass(IDEA.type+" "+IDEA.type+"-"+assigned).dblclick(IDEA.flash).click(IDEA.flip);
IDEA.followed($a,assigned+access);}
};
IDEA.fill=function(adjacent,album,ask,$all,already){
var s=fair(ask),sites=" ",i,pattern,site;
for(i=0;i<album.length;i++){
if(i){
$all.append($("<br />"));}
pattern=album[i];
site=pattern[0].replace(IDEA.re,s);
if(site!==already){
$all.append(IDEA.$forward(adjacent,site,pattern[1]));
if(already){
sites=sites+site+" ";}}}
if(already&&sites.indexOf(" "+already)<0){
$all.append($("<br />"))
.append(IDEA.$forward(adjacent,already,IDEA.flat(already)));}
};
IDEA.fire=function(){
var handler,i,scope;
for(i=0;i<IDEA.codes.length;i++){
scope=IDEA.codes[i];
handler=CHANCE[scope];
if(typeof handler.cfg==="object"){
if(typeof handler.features==="function"){
handler.features(handler);
}else{
IDEA.features(handler);}}}
mw.hook("wikipage.content").add(IDEA.furnish);
};
IDEA.first=function(){
var handler,s;
OO=window.OO;
IDEA.codes=[];
for(s in CHANCE){
handler=CHANCE[s];
if(handler.live){
switch(typeof IDEA.cfg[s]){
case "boolean":
if(!IDEA.cfg[s]){
handler.live=false;}
break;
case "object":
if(IDEA.cfg[s]){
handler.cfg=IDEA.cfg[s];}
break;}
if(handler.live&&(typeof handler.find!=="function"||typeof handler.resolver!=="object")){
handler.live=false;}
if(handler.live){
if(s==="www"){
if(IDEA.cfg.linking){
handler.shift=false;
}else{
handler.live=false;}
}else if(typeof handler.cfg==="object"&&typeof handler.cfg.shift==="string"&&handler.cfg.shift.indexOf("#")>0){
handler.shift=handler.cfg.shift;
}else{
handler.shift=false;}
if(handler.live){
IDEA.codes.push(s);}}}}
if(typeof IDEA.cfg.make==="number"){
IDEA.make=IDEA.cfg.make;
}else{
IDEA.make=0;}
IDEA.store="data-"+IDEA.type.toLowerCase()+"-";
IDEA.story=false;
IDEA.patterns={};
IDEA.re=new RegExp("#");
IDEA.types=false;
if(CHANCE.isbn.live){
CHANCE.isbn.feeder(IDEA.fire);
}else{
IDEA.fire();}
};
IDEA.flash=function(){
var msec=1000,that=this,$that=$(that),scope=$that.attr(IDEA.store+"scope"),state=IDEA.store+"state";
window.open($that.attr("data-href"),IDEA.fork(scope,"URL"));
window.setTimeout(function(){
if($that.attr(state)==="show"){
IDEA.flip.call(that);}
},msec);
};
IDEA.flat=function(address){
var got,n,parts,r,s,sub;
if(typeof IDEA.reAuth!=="object"){
IDEA.reAuth=new RegExp("^[^/]*//([^/:]+)(?::[0-9]+)?/");}
got=IDEA.reAuth.exec(address+"/");
if(got){
parts=got[1].toLowerCase().split(".");
n=parts.length-1;
if(n){
s=parts[n-1]+".";
r=s+parts[n];
if(n>1&&s.length<=4){
s="."+s;
if(n>1&&s.length<=4){
sub=".ac.com.co.edu.gov.gv.";
if(sub.indexOf(s)>=0){
r=parts[n-2]+"."+r;}}}}}
return r;
};
IDEA.flip=function(){
var $that=$(this),margin=10,start=$that.attr("data-href"),state=IDEA.store+"state",swap=IDEA.store+"popup",index=$that.attr(swap),slip=$that.attr(state),live,options,popup,scope,sign,signature,$e;
if(index){
index=parseInt(index,10);
popup=IDEA.popups[index];
live=(slip==="show");}
if(live){
slip="hide";
}else{
if(!popup){
if(typeof IDEA.cfg.illusive!=="number"){
if(IDEA.cfg.layer){
IDEA.cfg.illusive=1;
}else{
IDEA.cfg.illusive=IDEA.illusive;}}
index=IDEA.popups.length;
scope=$that.attr(IDEA.store+"scope");
sign=$that.attr(IDEA.store+"sign");
IDEA.followed($that,scope+sign,true);
options={align:"backwards",anchor:true,horizontalPosition:"end",padded:false,verticalPosition:"below",$floatableContainer:$that};
if(typeof CHANCE[scope].$fetch==="function"){
$e=CHANCE[scope].$fetch(sign,start);
}else{
$e=IDEA.$fetch(scope,sign,start);}
signature=IDEA.type+"_choice_"+index;
$e.addClass(IDEA.type+" "+IDEA.type+"-"+scope).attr({"id":signature})
.css({"font-family":"sans-serif",
"font-size":"medium",
"font-style":"normal",
"font-variant":"normal",
"text-align":"left"});
IDEA.$body.append($e);
$e=$("#"+signature);
options.height=$e.outerHeight()+margin+margin;
options.width=$e.outerWidth()+margin;
$e.detach().css({"visibility":"visible"});
options.$content=$("<div>").append($e).css({"padding":"3px"});
popup=new OO.ui.PopupWidget(options);
IDEA.popups.push(popup);
$that.attr(swap,index);
$e=popup.$element;
$e.attr({"id":IDEA.type+"_popup_"+index,
"role":"tooltip"}).css({"opacity":IDEA.cfg.illusive});
IDEA.$body.append(popup.$floatable);
if($that.hasClass(IDEA.type+"-www")){
sign=start;}
$that.attr("title",sign);
popup.$floatable.attr({"role":"tooltip"}).css({"opacity":IDEA.cfg.illusive,
"padding":"2px",
"text-align":"center"});}
slip="show";}
$that.attr(state,slip);
if(popup){
popup.toggle(slip==="show");}
return false;
};
IDEA.followed=function($a,assigned,apply){
var learnt=apply,sign,webSs,$children,$span;
if(!apply&&IDEA.story){
learnt=(IDEA.story.indexOf(" "+assigned+" ")>=0);
}else if(typeof window.sessionStorage==="object"){
webSs=window.sessionStorage;
if(webSs&&typeof webSs.getItem==="function"){
sign=IDEA.type+".visited";
try{
IDEA.story=webSs.getItem(sign);
if(IDEA.story){
IDEA.story=" "+IDEA.story+" ";
}else{
IDEA.story=" ";}
if(IDEA.story.indexOf(" "+assigned+" ")>=0){
learnt=true;
}else if(apply){
IDEA.story=IDEA.story+assigned;
if(typeof webSs.setItem==="function"){
webSs.setItem(sign,IDEA.story.substr(1));}
IDEA.story=IDEA.story+" ";}
}catch(e){
}}}
if(learnt){
$a.addClass(IDEA.type+"-visited");
if(!IDEA.cfg.light){
$children=$a.children();
if($children.length){
$children.css({"color":IDEA.seen});
}else{
$span=$("<span>");
$span.css({"color":IDEA.seen});
$span.text($a.text());
$a.text("");
$a.append($span);}}}
};
IDEA.fork=function(adjacent,at){
var r;
switch(IDEA.make){
case 0:
r=IDEA.type;
break;
case 1:
r=adjacent;
break;
case 2:
r=at;
break;
default:
r="_blank";}
return r;
};
IDEA.format=function($a,access){
var cfg,css,s,sign,type;
if(!IDEA.types){
IDEA.types=TYPES;
if(typeof IDEA.cfg.types==="object"){
for(sign in IDEA.cfg.types){
cfg=IDEA.cfg.types[sign];
if(!cfg){
IDEA.types[sign]=false;
}else if(typeof cfg==="object"&&typeof cfg.commons==="string"&&cfg.commons){
type=IDEA.types[sign];
type.commons=cfg.commons;
if(typeof cfg.ext==="string"&&cfg.ext){
type.ext=cfg.ext;}}}}
for(sign in IDEA.types){
type=IDEA.types[sign];
if(type&&typeof type.ext==="string"&&type.ext){
s="^(?:https?:)?//[^/]+/.+"+(typeof type.start==="string"?type.start:"\\.")+"("+type.ext.toUpperCase()+"|"+type.ext.toLowerCase()+")"+"(?:[/?&=#].*)?$";
type.re=new RegExp(s);
}else{
type.re=false;}}}
for(sign in IDEA.types){
type=IDEA.types[sign];
if(type&&type.re&&type.re.test(access)){
$a.addClass("url-type-"+sign);
if(typeof type.commons==="string"){
s="url(\"//upload.wikimedia.org/wikipedia/commons/"+type.commons+"\") "+"center right no-repeat";
css={"background":s,
"padding-right":"16px"};
$a.css(css);}
break;}}
};
IDEA.$forward=function(adjacent,address,as){
return $("<a>").attr({"href":address,
"target":IDEA.fork(adjacent,as),
"title":address}).text(as);
};
IDEA.furnish=function($area){
var i;
if(typeof IDEA.popups!=="object"){
IDEA.popups=[];}
IDEA.$body=$("body");
IDEA.$extiw=$area.find(".extiw");
IDEA.$external=$area.find(".external");
for(i=0;i<IDEA.codes.length;i++){
CHANCE[IDEA.codes[i]].find($area);}
mw.hook(IDEA.type+".changed").fire($area);
};
fire();
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>idResolver/core/r.js