User:PerfektesChaos/js/watchCategories/r.js

/// User:PerfektesChaos/js/watchCategories/r.js /// 2018-08-24 PerfektesChaos@de.wikipedia /// Fingerprint:#0#3A3FCB7E# /// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA) /// (function(mw,$){ "use strict"; var WatCat="watchCategories",Version=1.3; if(typeof mw.libs[WatCat]!=="object"||!mw.libs[WatCat]){ mw.libs[WatCat]={};} mw.libs[WatCat].type=WatCat; WatCat=mw.libs[WatCat]; WatCat.doc="w:en:User:PerfektesChaos/js/"+WatCat+""; WatCat.vsn=Version; function fire{ var signature="ext.gadget."+WatCat.type,rls; if(mw.loader.getState(signature)!=="ready"){ rls={}; rls[signature]="ready"; mw.loader.state(rls); if(WatCat.cats){ mw.loader.using(["user","mediawiki.api","mediawiki.util"],WatCat.fire);}}} WatCat.factory=function(already){ var r,s,v; if(already.cat){ r={}; for(s in already){ v=already[s]; if(v){ r[s]=v;}} r.cat=r.cat.replace(/_/g," "); if(typeof(r.min)!=="number"){ r.min=1;} if(typeof(r.ns)!=="number"){ r.ns=-1;} if(r.ns===-1&&typeof(r.title)!=="string"){ r.title="Watchlist";} if(typeof(r.append)!=="string"&&typeof(r.before)!=="string"){ if(r.ns===-1&&r.title==="Watchlist"){ r.before="#mw-content-text"; }else{ r.before=mw.util.$content;}} if(typeof(r.style1)!=="string"){ r.style1="border: solid 2px #FF0000; padding: 3px; color: #FF0000;";} if(r.min<1&&typeof(r.style0)!=="string"){ r.style0="border: solid 1px #008000; padding: 3px; color: #008000;";}} return r; }; WatCat.find=function{ var e,i,s; var n=this.q.length; var sP=false; var sT=false; for(i=n-1;i>=0;i--){ e=this.q[i]; if(e.ns===this.nsN&&e.title===this.title){ switch(typeof(e.cat)){ case "string": s="Category:"+e.cat; if(sT){ sT=sT+"|"+s; }else{ sT=s;} break; case "number": e.curid=e.cat; delete e.cat; if(sP){ sP=sP+"|"; }else{ sP="";} sP=sP+e.curid; break;} }else{ this.q[i]=false;}} if(sP||sT){ this.reSp=new RegExp(" ","g"); this.space=mw.config.get("wgFormattedNamespaces")[14];} if(sP){ this.finder(sP,false);} if(sT){ sT=sT.replace(this.reSp,"_"); this.finder(sT,true);} }; WatCat.finder=function(ask,assigned){ var a=new mw.Api; var o={action:"query",prop:"categoryinfo"}; if(assigned){ o.titles=ask; }else{ o.pageids=ask;} a.get(o).done(this.found); }; WatCat.fire=function{ var e,i,n,launch=false; WatCat.nsN=mw.config.get("wgNamespaceNumber"); if(WatCat.nsN===-1){ WatCat.title=mw.config.get("wgCanonicalSpecialPageName");} switch(typeof(WatCat.cats)){ case "string": case "number": if(WatCat.nsN===-1){ if(WatCat.title==="Watchlist"){ WatCat.q=[WatCat.factory({cat:WatCat.cats})]; launch=true;}} break; case "object": n=WatCat.cats.length; if(typeof(n)==="number"){ if(WatCat.nsN!==-1){ WatCat.title=mw.config.get("wgTitle");} WatCat.q=[]; for(i=0;i=adhere.min){ s=" "+(typeof(alter)==="string"?alter:about)+""+(amount?" # "+amount+" ":"")+" "; if(adhere.append){ this.furnish(s,adhere.append,true); }else if(adhere.before){ this.furnish(s,adhere.before,false);}} }; WatCat.found=function(arrived){ var e,g,i,p,s,got=arrived.query,j=WatCat.space.length+1,n=WatCat.q.length; if(got){ got=got.pages; if(got){ for(g in got){ p=got[g]; for(i=0;i<n;i++){ e=WatCat.q[i]; if(p&&e){ if(p.title){ s=p.title.substr(j); if(typeof(p.pageid)!=="number"){ p.pageid=-2;} if(p.pageid===e.curid||s===e.cat){ p=p.categoryinfo; if(p){ WatCat.flag(e,s,p.pages,e.text);}}}}}}}} }; WatCat.furnish=function(apply,adjacent,append){ var $e; var $i=$(apply); switch(typeof(adjacent)){ case "string": $e=$(adjacent); break; case "object": $e=adjacent; break; default: $e=false;} if(!$e.length){ $e=mw.util.$content;} if(append){ $e.append($i); }else{ $e.before($i);} }; fire; }(window.mediaWiki,window.jQuery)); /// EOF watchCategories/r.js