Jump to content

User:PerfektesChaos/js/refNames/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/refNames/r.js
/// 2022-07-27 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#354984A2#
/// License:CC-by-sa/4.0
///<nowiki>
(function(mw){
"use strict";
var Version=1.3,Signature="refNames",THIS={doc:{site:"w:en",support:"User:PerfektesChaos/js/"+Signature},launch:false,learn:false,maxage:43200,rooms:[0,2,4],shoot:false,site:"w:en",spaces:false,store:"User:PerfektesChaos/js/",strange:false,sub:"core",using:["mediawiki.util"],warn:false
},PREGO={app:false,live:false,maxage:604816,pars:[["spaces","string"],["strange","string"],["shoot","string"]],signature:"preferencesGadgetOptions",site:"w:en",store:"User:PerfektesChaos/js/",sub:"/r.js"},REPOS={};
function features(apply){
var i,n,rooms,s;
if(typeof apply==="object"&&apply){
if(typeof apply.rooms==="object"&&apply.rooms&&typeof apply.rooms.length==="number"){
rooms=[];
for(i=0;i<apply.rooms.length;i++){
n=apply.rooms[i];
if(typeof n==="number"){
n=Math.floor(n);
if(n>=0){
rooms.push(n);}}}
if(rooms.length){
rooms.sort();
THIS.rooms=rooms;}
}else if(typeof apply.rooms==="string"){
THIS.spaces="*";}
if(THIS.learn&&typeof apply.trigger==="object"&&apply.trigger&&typeof apply.trigger.length==="number"){
for(i=0;i<apply.trigger.length;i++){
if(apply.trigger[i]===THIS.nsn){
THIS.launch=true;
break;}}}
if(typeof apply.warn==="string"){
apply.warn=apply.warn.trim();
if(apply.warn){
THIS.warn=THIS.warn||[];
THIS.warn.push(apply.warn);}
}else if(typeof apply.warn==="object"&&apply.warn&&typeof apply.warn.length==="number"){
for(i=0;i<apply.warn.length;i++){
s=apply.warn[i];
if(typeof s==="string"){
s=s.trim();
if(s){
THIS.warn=THIS.warn||[];
THIS.warn.push(s);}}}}}}
function feed(access){
var sign=THIS.signature+".",store=THIS.store+Signature,rls;
if(access&&typeof access==="string"){
sign=sign+access;
store=store+"/"+access;
}else{
REPOS.fire(THIS.site,store+".css",false,{action:"raw",ctype:"text/css",bcache:1,maxage:THIS.maxage});
THIS.serial=Version+"";
mw.hook(Signature+"."+THIS.sub).fire(THIS);
sign=sign+THIS.sub;
store=store+"/"+THIS.sub;}
if(!mw.loader.getState(sign)){
rls={};
rls[sign]="loading";
mw.loader.state(rls);
REPOS.fire(THIS.site,store,(Version>0?"/r.js":"/d.js"),{action:"raw",ctype:"text/javascript",bcache:1,maxage:THIS.maxage});}}
function first(){
var env,i,live,rls,s;
THIS.signature="ext.gadget."+Signature;
if(mw.loader.getState(THIS.signature)!=="ready"){
rls={};
rls[THIS.signature]="ready";
mw.loader.state(rls);
env=mw.config.get(["wgAction","wgNamespaceNumber"]);
THIS.nsn=env.wgNamespaceNumber;
switch(env.wgAction){
case "edit":
case "submit":
live=true;
THIS.learn=true;
break;
case "view":
if(THIS.nsn===-1){
if(mw.config.get("wgCanonicalSpecialPageName")==="Blankpage"){
s=mw.config.get("wgTitle");
i=s.indexOf("/"+PREGO.signature);
if(i>1){
PREGO.live=true;}}
}else{
live=true;}
break;}
if(live){
live=(mw.config.get("wgPageContentModel")==="wikitext");}
if(live||PREGO.live){
mw.hook(Signature+".config").add(features);
THIS.doc.server=REPOS.foundation(THIS.doc.site,"");
PREGO.feed();
mw.hook(PREGO.signature+".fetch").fire(Signature,PREGO.features);}
THIS.pub={doc:"[["+THIS.doc.site+":"+THIS.doc.support+"]]",type:Signature,vsn:Version};
mw.hook(Signature+".ready").fire(THIS.pub);}}
PREGO.features=function(applied){
var re=new RegExp("\\s+"),i,live,n,s,v;
if(typeof applied==="object"&&applied){
n=PREGO.pars.length;
for(i=0;i<n;i++){
v=PREGO.pars[i];
s=v[0];
if(typeof applied[s]===v[1]){
THIS[s]=applied[s];}}}
if(THIS.shoot){
THIS.shoot=THIS.shoot.trim().replace(re," ");}
if(THIS.spaces){
THIS.spaces=THIS.spaces.trim().replace(re," ");
}else{
n=false;
THIS.rooms.sort();
for(i=0;i<THIS.rooms.length;i++){
if(THIS.rooms[i]!==n){
n=THIS.rooms[i];
THIS.spaces=(THIS.spaces?THIS.spaces+" ":"")+n;}}}
if(THIS.strange){
THIS.strange=THIS.strange.trim();}
if(PREGO.live){
THIS.prego={pars:PREGO.pars,signature:PREGO.signature};
mw.hook(Signature+".prego").fire(THIS);
feed("prego");
}else{
if(THIS.spaces==="*"){
live=true;
}else if(THIS.spaces&&THIS.spaces!=="-"){
v=THIS.spaces.split(" ");
s=THIS.nsn+"";
for(i=0;i<v.length;i++){
if(s===v[i]){
live=true;
break;}}}
if(live&&THIS.learn&&THIS.shoot){
v=THIS.shoot.split(" ");
s=THIS.nsn+"";
for(i=0;i<v.length;i++){
if(s===v[i]){
THIS.launch=true;
break;}}}
if(THIS.strange==="-"){
THIS.strange=false;}
if(THIS.strange){
THIS.warn=THIS.warn||[];
THIS.warn.push(THIS.strange);}
if(live){
mw.loader.using(THIS.using,feed);}}
};
PREGO.feed=function(){
var sign="ext.gadget."+PREGO.signature,rls;
if(!mw.loader.getState(sign)){
rls={};
rls[sign]="loading";
mw.loader.state(rls);
REPOS.fire(PREGO.site,PREGO.store+PREGO.signature+PREGO.sub,false,{action:"raw",ctype:"text/javascript",bcache:1,maxage:PREGO.maxage});}
};
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</nowiki>refNames/r.js