User:PerfektesChaos/js/jsonDebug/scout/r.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:PerfektesChaos/js/jsonDebug/scout/r. |
/// User:PerfektesChaos/js/jsonDebug/scout/r.js
/// 2018-08-24 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#1476A92A#
/// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA)
///<nowiki>
(function(mw){
"use strict";
var Version=1.1,Signature="scout",APP={listen:false,loading:false,longer:false,nsn:false,reClass:false,reTag:false,rooms:false,sel:false,sign:false},JSOND={sign:"jsonDebug",site:"w:en",store:"User:PerfektesChaos/js/",sel:"json-code-lint",src:"div,pre",using:null},REPOS={requests:false};
APP.feed=function(area){
var nsn,s;
if(!APP.listen){
switch(typeof area){
case "number":
nsn=area;
break;
case "string":
if(!APP.rooms){
APP.rooms=mw.config.get("wgNamespaceIds");
APP.reSpace=new RegExp("\\s+");}
s=area.trim().replace(APP.reSpace,"_").toLowerCase();
if(typeof APP.rooms[s]==="number"){
nsn=APP.rooms[s];}
break;}
if(typeof nsn==="number"){
APP.listen=(APP.nsn===nsn);
if(APP.listen){
APP.finder();}}}
};
APP.fetch=function(){
var p,suffix;
p={bcache:1};
if(APP.longer){
p.maxage=100;
suffix="/d.js";
}else{
p.maxage=604800;
suffix="/r.js";}
REPOS.fire(JSOND.site,JSOND.store+JSOND.sign,suffix,p);
};
APP.find=function($area){
if(!APP.sel){
APP.sel="."+JSOND.sel;}
if($area.find(APP.sel).filter(JSOND.src).length){
APP.loading=true;
APP.fetch();}
};
APP.finder=function(){
mw.hook("wikipage.content").add(APP.find);
};
APP.fire=function(areas,assert){
var i;
if(typeof assert==="boolean"){
APP.longer=assert;}
if(!APP.listen){
if(typeof areas==="object"){
if(areas&&typeof areas.length==="number"){
for(i=0;i<areas.length;i++){
APP.feed(areas[i]);}}
}else{
APP.feed(areas);}}
};
APP.first=function(){
var env,rls;
if(!APP.sign){
APP.sign=JSOND.sign+"."+Signature;
APP.signature="ext.gadget."+APP.sign;}
if(mw.loader.getState(APP.signature)!=="ready"){
rls={};
rls[APP.signature]="ready";
mw.loader.state(rls);
mw.hook(APP.sign+".ready").fire({type:APP.sign,vsn:Version});
env=mw.config.get(["wgPageContentModel","wgNamespaceNumber"]);
if(env.wgPageContentModel.toLowerCase().indexOf("json")>=0){
APP.fetch();
}else{
APP.nsn=env.wgNamespaceNumber;
mw.hook(JSOND.sign+".namespaces").add(APP.fire);
mw.hook(JSOND.sign+".selectors").add(APP.further);}}
};
APP.further=function(add){
var i,s;
if(!APP.loading&&typeof add==="object"&&add){
if(typeof add.classes==="object"&&add.classes&&typeof add.classes.length==="number"){
if(!APP.reClass){
APP.reClass=new RegExp("^[^ .#,]+$");}
if(!APP.sel){
APP.sel="."+JSOND.sel;}
for(i=0;i<add.classes.length;i++){
s=add.classes[i];
if(APP.reClass.test(s)){
APP.sel=APP.sel+",."+s;}}}
if(typeof add.tags==="object"&&add.tags&&typeof add.tags.length==="number"){
if(!APP.reTag){
APP.reTag=new RegExp("^[a-zA-Z]+$");}
for(i=0;i<add.tags.length;i++){
s=add.tags[i];
if(APP.reTag.test(s)){
JSOND.src=JSOND.src+","+s;}}}
if(APP.listen){
APP.finder();}}
};
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;
};
APP.first();
}(window.mediaWiki));
/// EOF</nowiki>jsonDebug/scout/r.js