User:PerfektesChaos/js/pageTeaserHint/r.js

/// User:PerfektesChaos/js/pageTeaserHint/r.js /// 2020-12-27 PerfektesChaos@de.wikipedia /// Fingerprint:#0#3CDAA807# /// License:CC-by-sa/4.0 /// (function(mw,$){ "use strict"; var Version=1.5,Signature="pageTeaserHint",Store="User:PerfektesChaos/js/"+Signature,PTH={core:{maxage:86400,site:"w:en",store:Store,sub:"core"},doc:{site:"w:en",store:Store},got:false,lazy:true,limited:true,paged:{"allpages": {suite:".mw-allpages-nav",search:".mw-allpages-body" },"category": {suite:"#mw-pages",search:"#mw-pages" },"contributions": {suite:".mw-contributions-list",search:"#mw-content-text" },"info": {suite:"#mw-pageinfo-header-restrictions",search:false },"prefixindex": {suite:".mw-prefixindex-body",search:".mw-prefixindex-body" },"search": {suite:".mw-search-results",search:".mw-search-results" },"whatlinkshere": {suite:"#mw-whatlinkshere-list",search:"#mw-content-text" } },pages:{"*":{button:{large:true },list:true}, "info":{button:{large:false },list:true}, "search":{button:{large:true },list:false}, "user":{button:{large:false },list:true} },re:false,result:false,rooms:false,scope:false,trigger:{src:"OOjs UI icon window-invert.svg",sub:"ec" },$widget:false },REPOS={}; PTH.REPOS=REPOS; function face{ if(!PTH.$body){ PTH.$body=$("body"); PTH.ltr=($("html").attr("dir")!=="rtl");}} function factory(area,at,$a){ var r=at; if(area&&(area<0||PTH.limited||area%2)){ r=false;} if(r&&(area===2||area===6||area===8||area===14)){ r=false;} if(r&&area&&PTH.limited){ r=false;} if(r){ r=r.replace(PTH.re.usc," "); PTH.got=PTH.got||{}; if(typeof PTH.got[r]!=="object"){ PTH.got[r]={ns:area,show:r,ul:[] };} if($a){ PTH.got[r].ul.push($a);}} return r;} function feed{ mw.hook(Signature+".init").fire(PTH);} function feeder{ if(PTH.core){ PTH.core.suite=(Version>1?"r":"d"); if(PTH.core.suite!=="r"){ PTH.core.maxage=100;} REPOS.fire(PTH.core.site,PTH.core.store,"/"+PTH.core.sub+"/"+PTH.core.suite+".js",{maxage:PTH.core.maxage}); PTH.core=false; mw.loader.using(["mediawiki.api","mediawiki.storage","mediawiki.util"],feed);}} function fetch{ var $ajax=$(" "); PTH.$widget.empty; $ajax.addClass("mw-ajax-loader",PTH.selector+"ajax").css({"margin-bottom":"0.2em", "margin-left":"1em", "margin-right":"1em", "margin-top":"0.2em"}).text(" "); PTH.$widget.append($ajax); feeder; mw.hook(Signature+".result").fire(PTH.got,PTH.page);} function fiat(at,assigned){ var $a=$(assigned),s=$a.attr("href"),got,i,ns,space; if(s.substr(0,6)==="/wiki/"){ s=s.substr(6); }else{ got=PTH.re.abs.exec(s); if(got){ s=got[1]; }else{ s=false;}} if(s){ i=s.indexOf("#"); if(i>0){ s=s.substr(0,i);} try{ s=decodeURIComponent(s); }catch(e){ } got=PTH.re.sns.exec(s); if(got){ space=got[1].toLowerCase; if(typeof PTH.rooms[space]==="number"){ ns=PTH.rooms[space];}} if(s){ ns=ns||0; if(factory(ns,s,$a)){ PTH.page.learnt=true; if(!ns){ PTH.lazy=false;}}}}} function finesse{ var cnf=mw.config.get(["wgPageContentModel","wgTitle"]); if(cnf.wgPageContentModel==="wikitext"&&factory(PTH.nsn,cnf.wgTitle)){ if(!PTH.nsn){ PTH.lazy=false;} PTH.page.learnt=true;}} function fire{ var button,seek,$got; switch(PTH.scope){ case "allpages": case "contributions": case "prefixindex": case "whatlinkshere": case "category": PTH.page=PTH.pages["*"]; break; default: PTH.page=PTH.pages[PTH.scope];} PTH.page.learnt=false; button=PTH.page.button; button.fiat=fetch; button.sel=PTH.paged[PTH.scope].suite; button.support=Signature+" "+Version; PTH.page.search=PTH.paged[PTH.scope].search; if(PTH.page.search){ PTH.page.$container=$(PTH.page.search); seek="a[href*=\"/wiki/\"]:not(a[href*=\"#\"])"; $got=PTH.page.$container.find(seek); if(PTH.scope!=="user"){ $got.not(".mw-parser-output a");} $got.each(fiat); }else{ finesse;} if(PTH.page.learnt){ PTH.furnish(PTH.page.button);} delete PTH.page.learnt;} function firing(apply){ var cnf,listen,s; mw.hook(Signature+".config").remove(firing); if(PTH.scope===false){ PTH.scope=null; cnf=mw.config.get(["wgAction","wgPageContentModel","wgNamespaceIds","wgNamespaceNumber"]); PTH.rooms=cnf.wgNamespaceIds; PTH.nsn=cnf.wgNamespaceNumber; PTH.selector=Signature.toLowerCase+"-"; if(typeof apply==="object"&&apply){ if(typeof apply.limited==="boolean"){ PTH.limited=apply.limited;} if(typeof apply.listen==="boolean"){ listen=apply.listen; PTH.paged.user={suite:"."+PTH.selector+"private",search:"."+PTH.selector+"private" };}} switch(cnf.wgAction){ case "view": if(PTH.nsn===-1){ s=mw.config.get("wgCanonicalSpecialPageName"); switch(s){ case "Allpages": case "Contributions": case "Prefixindex": case "Search": case "Whatlinkshere": PTH.scope=s.toLowerCase; break;} }else if(cnf.wgPageContentModel==="wikitext"&&PTH.nsn){ if(PTH.nsn===14){ PTH.scope="category"; }else if(listen){ PTH.scope="user";}} break; case "edit": case "submit": if(listen&&cnf.wgPageContentModel==="wikitext"&&PTH.nsn){ PTH.scope="user";} break; case "info": if(!(PTH.nsn&&apply.limited)&&PTH.nsn!==14){ PTH.scope="info";} break;} if(PTH.scope){ PTH.re={abs:new RegExp("^(?:[htps]*:)?//[^/]+/wiki/(.+)$"),sns:new RegExp("^([^:]+):"),spc:new RegExp(" ","g"),usc:new RegExp("_","g"),wsp:new RegExp("^\\s*$")}; $(fire);}}} function first{ var rls,s; PTH.signature="ext.gadget."+Signature; if(mw.loader.getState(PTH.signature)!=="ready"){ rls={}; rls[PTH.signature]="ready"; mw.loader.state(rls); s=""+PTH.doc.site+"/"+PTH.doc.store+""; PTH.pub={doc:s,signature:PTH.signature,type:Signature,vsn:Version}; mw.hook(Signature+".ready").fire(PTH.pub); mw.hook(Signature+".config").add(firing); mw.hook(Signature+".config").fire;}} PTH.$file=function(access,appear){ var $r=$(" "),obj,src; if(typeof access==="object"&&access&&typeof appear==="number"&&appear>0){ if(typeof access.ltr==="object"&&access.ltr&&typeof access.rtl==="object"&&access.rtl){ obj=access[(this.ltr?"ltr":"rtl")]; }else{ obj=access;} if(typeof obj.src==="string"&&obj.src&&typeof obj.sub==="string"&&obj.sub.length===2){ src=obj.src.replace(PTH.re.spc,"_"); $r.attr({"src":"https://upload.wikimedia.org/wikipedia/commons/thumb/"+obj.sub.substr(0,1)+"/"+obj.sub+"/"+src+"/"+appear+"px-"+src+".png" }).css({"display":"inline"}); }else{ window.console.log(Signature+".$file s",access);} }else{ window.console.log(Signature+".$file *",access,appear);} return $r; }; PTH.furnish=function(apply){ var css={"background-color":"#3366CC", "border":"1px solid #3366CC", "border-radius":"2px", "color":"#FFFFFF", "cursor":"pointer", "display":"table", "padding":"0.546875em 1em", "text-align":"center", "vertical-align":"middle" },$btn=$(" "),img,trigger,$img,$rel; if(!this.$widget){ mw.loader.load("mediawiki.ui.button"); this.$widget=$(" "); this.$widget.addClass(this.selector+"widget"); face; this.$widget.css({"float": (this.ltr?"right":"left")}); $rel=$(apply.sel); $rel.eq(0).before(this.$widget);} trigger=this.trigger; if(typeof trigger.ltr==="object"){ trigger=trigger[(this.ltr?"ltr":"rtl")];} img=(apply.large?30:18); $img=this.$file(trigger,img); $btn.addClass(["mw-ui-button","mw-ui-progressive",this.selector+"-button"]).append($img).attr({"role":"button", "title":apply.support}).click(apply.fiat).css(css); this.$widget.append($btn); }; REPOS.fire=function(at,access,append,alter){ var source,syntax; if(typeof REPOS.requests!=="object"){ REPOS.requests={};} if(typeof REPOS.requests[access]!=="boolean"){ REPOS.requests[access]=true; if(append){ source=access+append; }else{ source=access;} if(at){ source=REPOS.foundation(at,source,alter); if(typeof alter==="object"&&alter&&typeof alter.ctype==="string"){ syntax=alter.ctype;} }else{ syntax=alter;} mw.loader.load(source,syntax);} }; REPOS.foundation=function(at,access,alter){ var s=access,r=encodeURI(s); if(typeof alter==="object"&&alter){ r="/w/index.php?title="+r; if(access.substr(-3)===".js"){ alter.ctype="text/javascript"; }else if(access.substr(-4)===".css"){ alter.ctype="text/css";} alter.action="raw"; for(s in alter){ r=r+"&"+s+"="+encodeURI(alter[s]);} }else{ r="/wiki/"+r;} if(typeof at==="string"&&at){ switch(at){ case "meta": r="meta.wikimedia.org"+r; break; case "mw": r="www.mediawiki.org"+r; break; case "w:en": r="en.wikipedia.org"+r; break; default: r=window.location.host+r;} r="https://"+r;} return r; }; first; }(window.mediaWiki,window.jQuery)); /// EOF pageTeaserHint/r.js