Jump to content

User:PerfektesChaos/js/superscriptMagnifier/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/superscriptMagnifier/r.js
/// 2018-08-24 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#279A6FAC#
/// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA)
///<nowiki>
(function(mw,$){
"use strict";
var Version=1.1,SSM="superscriptMagnifier",Config={dewiki:[5551,1014413,34226,9135891],enwiki:[48934384]
},SuMag;
if(typeof mw.libs[SSM]!=="object"||!mw.libs[SSM]){
mw.libs[SSM]={};}
mw.libs[SSM].type=SSM;
SSM=mw.libs[SSM];
if(typeof SSM.vsn==="undefined"){
SSM.vsn=Version;
SSM.signature="ext.gadget."+SSM.type;
SSM.support="User:PerfektesChaos/js/"+SSM.type;
SSM.doc="[[w:en:"+SSM.support+"]]";}
SuMag=(function($){
var config={large:false,latin:true,max:false,sign:false},offer={},transl={178:"2",179:"3",185:"1",0x0656:0x0627,0x1D62:"i",0x1D63:"r",0x1D64:"u",0x1D65:"v",0x1D66:0x03B2,0x1D67:0x03B3,0x1D68:0x03C1,0x1D69:0x03C6,0x1D6A:0x03C7,0x2070:"0",0x2071:"i",0x2074:"4",0x2075:"5",0x2076:"6",0x2077:"7",0x2078:"8",0x2079:"9",0x207A:"+",0x207B:0x2212,0x207C:"=",0x207D:"(",0x207E:")",0x207F:"n",0x2080:"0",0x2081:"1",0x2082:"2",0x2083:"3",0x2084:"4",0x2085:"5",0x2086:"6",0x2087:"7",0x2088:"8",0x2089:"9",0x208A:"+",0x208B:0x2212,0x208C:"=",0x208D:"(",0x208E:")",0x2090:"a",0x2091:"e",0x2092:"o",0x2093:"x",0x2094:0x0259,0x2095:"h",0x2096:"k",0x2097:"l",0x2098:"m",0x2099:"n",0x209A:"p",0x209B:"s",0x209C:"t",0x2C7C:"j"},needles,needlesX,reGet,reHas;
function facet(apply){
var k=apply.charCodeAt(0),light=(k<256),low=false,s,$r;
if(light){
needles++;
}else{
needlesX++;
low=((k>=0x1D62&&k<=0x1D65)||(k>=0x2080&&k<=0x209C));
if(!config.latin){
low=low||(k>=0x1D66&&k<=0x03C7);}}
$r=$(low?"<sub>":"<sup>");
s=transl[k];
if(typeof s==="number"){
s=String.fromCharCode(s);}
$r.text(s);
if(config.sign){
$r.addClass(config.sign);
if(!light){
$r.addClass(config.sign+"-ucs");
if(config.scream){
$r.addClass(config.scream);}}}
return $r;}
function fair(adjust){
var s=adjust,$r=$("<span>"),got;
while(s){
got=reGet.exec(s);
if(got){
if(got[1]){
$r.append($("<span>").text(got[1]));}
$r.append(facet(got[2]));
s=got[3];
}else{
$r.append($("<span>").text(s));
s=false;}}
return $r;}
function feed($assembly){
var skip=" code form pre ",s=$assembly.text(),i,el,$cont;
if(config.max&&s.length>config.max){
s="";}
if(reHas.test(s)){
$cont=$assembly.contents();
for(i=$cont.length-1;i>=0;i--){
el=$cont.get(i);
switch(el.nodeType){
case 1:
s=" "+el.nodeName.toLowerCase()+" ";
if(skip.indexOf(s)<0){
feed($cont.eq(i));}
break;
case 3:
s=el.nodeValue;
if(reHas.test(s)){
el.nodeValue="";
$cont.eq(i).after(fair(s));}
break;}}}}
offer.factory=function(assign,apply){
var s;
if(typeof assign==="string"){
config[assign]=apply;
if((assign==="latin"&&!apply)||(assign==="scream"&&apply)){
config.large=true;}
}else{
s="²³¹";
if(config.large){
s=s+String.fromCharCode(0x1D62,45,0x1D65,0x2070,0x2071,0x2074,45,0x208E,0x2090,45,0x209C);
if(!config.latin){
s=s+String.fromCharCode(0x0656,0x1D66,45,0x1D6A);}}
reGet=new RegExp("^([^"+s+"]*)(["+s+"])(.*)$");
reHas=new RegExp("["+s+"]");}
};
offer.fire=function($assembly){
needles=0;
needlesX=0;
feed($assembly);
};
offer.found=function(alter){
return(alter?needlesX:needles);
};
return offer;
})($);
function fiat($assembly){
var nA,nU,show,sign,$a,$div,$span;
if(!$("#wikiDiff").length){
SuMag.fire($assembly);
if(SSM.locator){
sign=SSM.type+"-info";
$("#"+sign).remove();
nA=SuMag.found();
nU=SuMag.found(true);
if(nA+nU){
show=nA+"";
if(nU){
show=show+" / "+nU;}
$a=$("<a>");
$a.attr({"href":"//en.wikipedia.org/wiki/"+SSM.support}).text(SSM.support);
$span=$("<span>");
$span.css({"margin-left":"2em"}).text(show);
$div=$("<div>");
$div.append($a,$span).attr({"class":SSM.type,"id":sign})
.css({"border":"#808080 1px solid","margin-bottom":"1em",
"margin-top":"1em","padding":"0.8em"});
$assembly.append($div);}}}}
function fill(){
var exceptions;
if(typeof Config[SSM.wgDBname]==="object"){
exceptions=Config[SSM.wgDBname];
}else{
exceptions=[];}
if(typeof SSM.except==="object"&&SSM.except&&typeof SSM.except.length==="number"){
exceptions.concat(SSM.except);}
if($.inArray(SSM.wgArticleId,exceptions)<0){
if(typeof SSM.lapsus==="boolean"){
SuMag.factory("scream","error");
SSM.locator=true;}
if(typeof SSM.large==="boolean"){
SuMag.factory("large",SSM.large);}
if(typeof SSM.latin==="boolean"){
SuMag.factory("latin",SSM.latin);}
if(typeof SSM.locator==="boolean"&&SSM.locator){
SuMag.factory("sign",SSM.type);}
if(typeof SSM.max==="number"&&SSM.max>0){
SuMag.factory("max",SSM.max);}
SuMag.factory();
mw.hook("wikipage.content").add(fiat);}}
function fire(){
var env,rls;
if(mw.loader.getState(SSM.signature)!=="ready"){
rls={};
rls[SSM.signature]="ready";
mw.loader.state(rls);
env=mw.config.get(["wgAction","wgArticleId","wgDBname","wgNamespaceNumber"]);
if(env.wgNamespaceNumber>=0&&"|edit|submit|view|".indexOf(env.wgAction)>0){
SSM.wgArticleId=env.wgArticleId;
SSM.wgDBname=env.wgDBname;
mw.loader.using(["user"],fill);}
mw.hook(SSM.type+".ready").fire();}}
fire();
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>superscriptMagnifier/r.js