User:PerfektesChaos/js/fragmentAnchors/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. |
This user script seems to have a documentation page at User:PerfektesChaos/js/fragmentAnchors/r. |
/// Gadget/fragmentAnchors/r.js
/// 2021-07-30 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#378F0A71#
/// Documentation:[[w:en:User:PerfektesChaos/js/fragmentAnchors]]
/// @license:CC-by-sa/4.0 GPLv3
///<nowiki>
(function(mw,$){
"use strict";
var Version=2.7,FANCY="fragmentAnchors",FASC={cfg:{},siblings:"error-repeated-id",source0:"6/62/Anchor_pictogram.svg",source1:"d/d6/Anchor_pictogram_red.svg",unStart:["wpTextbox","/maplink/","Anker:"],vsn:Version
},EXPORT={},OO;
function facet($area){
mw.hook("wikipage.content").remove(facet);
FASC.$content=$area;
if(FASC.locked){
FASC.$exclude=false;
}else{
FASC.$exclude=FASC.$content.find("form");}
FASC.furnish();}
function facility(){
OO=window.OO;
if(FASC.large){
FASC.$content=false;
FASC.$exclude=false;
FASC.furnish();
}else{
mw.hook("wikipage.content").add(facet);}}
function fiat(){
FASC.cfg.live=false;
if(typeof FASC.cfg.$portlet==="object"){
FASC.cfg.$portlet.hide();}
mw.loader.using(["oojs","oojs-ui-core","oojs-ui-widgets"],facility);}
function fire(){
var signature="ext.gadget."+FANCY,env,rls;
if(mw.loader.getState(signature)!=="ready"){
rls={};
rls[signature]="ready";
mw.loader.state(rls);
if(typeof mw.libs[FANCY]!=="object"||!mw.libs[FANCY]){
mw.libs[FANCY]={};}
mw.libs[FANCY].type=FANCY;
FANCY=mw.libs[FANCY];
FANCY.vsn=Version;
FANCY.doc="w:en:User:PerfektesChaos/js/"+FANCY.type;
FANCY.doc="[["+FANCY.doc+"]]";
FANCY.fetch=EXPORT.fetch;
FANCY.fire=EXPORT.fire;
env=mw.config.get(["wgAction","wgPageContentModel"]);
FASC.cfg.live=false;
if(env.wgPageContentModel==="wikitext"){
FASC.locked=(env.wgAction==="view");
FASC.sign=FANCY.type;
mw.loader.using(["user","mediawiki.util"],FASC.fire);}}}
function freshed(){
FASC.cfg.live=true;
FASC.cfg.$portlet.show();}
EXPORT.fetch=function(){
var dup,r,s;
if(FASC.cfg.live){
FASC.learn=false;
fiat();
if(FASC.dup){
dup={};
for(s in FASC.dup){
dup[s]=FASC.dup[s].length;}
}else{
dup=false;}
r=[FASC.total,dup,FASC.want];
}else{
r=false;}
return r;
};
EXPORT.fire=function(){
var r=FASC.cfg.live;
if(r){
fiat();}
return r;
};
FASC.cfg.escape=function(anchor){
return mw.html.escape(anchor);
};
FASC.cfg.fair=function(anchor,allow){
var r,s;
if(allow){
r=anchor;
}else{
r=anchor.replace(/_/g," ");}
if(typeof FASC.cfg.wikiAnchor!=="object"){
s="[0-9A-Fa-f]";
s="\\.("+s+s+")";
FASC.cfg.wikiAnchor=new RegExp(s,"g");}
try{
s=r.replace(FASC.cfg.wikiAnchor,"%$1");
r=decodeURIComponent(s);
}catch(e){
}
return r;
};
FASC.cfg.familiar=function(anchor,$at){
var s=FASC.cfg.fair(anchor,true),r,$e;
if(s!==anchor&&$at.is("span")){
$e=$at.next();
r=($e.is("span")&&"#"+$e.attr("id")===s);
if(!r){
$e=$at.prev();
r=($e.is("span")&&"#"+$e.attr("id")===s);}}
return r;
};
FASC.cfg.fancy=function(anchor){
return "[["+anchor+"]]";
};
FASC.cfg.fire=function(){
var launch,lock,portlet;
FASC.$body=$("body");
if(typeof FANCY.large==="boolean"){
FASC.large=FANCY.large;}
if(typeof FANCY.launch==="boolean"){
launch=FANCY.launch;}
if(typeof FANCY.lock==="boolean"){
lock=FANCY.lock;}
FASC.learn=true;
if(!(lock||launch)){
portlet=mw.util.addPortletLink("p-tb","#"," ","t-"+FASC.sign);
FASC.cfg.$portlet=$(portlet);
FASC.cfg.$portlet.append(FASC.$facet());
FASC.cfg.$portlet.click(fiat);
FASC.cfg.$portlet.attr({title:FASC.sign+" "+FASC.vsn});
mw.hook("wikipage.content").add(freshed);}
mw.hook(FANCY.type+".ready").fire(FANCY);
if(launch){
fiat();
}else{
FASC.cfg.live=true;}
};
FASC.cfg.$flag=function(){
return $("h1").eq(0);
};
FASC.$facet=function(alert,augment){
var m=(alert||augment?1:0),n=(alert?20:12),s=FASC["source"+m],$r=$("<img />");
$r.attr({alt:"id?",src:"https://upload.wikimedia.org/wikipedia/commons/thumb/"+s+"/"+n+"px-"+s.substr(5)+".png"});
$r.css({"height":n,
"width":n});
if(alert){
$r.css({"background-color":"#FFFF00",
"border":"#FF0000 2px solid",
"padding":"1px"});}
return $r;
};
FASC.$factory=function(about){
var badge=FASC.badges[about.mode],$i,$r;
if(!badge){
badge={};
badge.$i=FASC.$facet((about.mode===1),(about.mode===2));
badge.$i.addClass(FASC.show);
if(about.mode===1){
badge.$i.addClass(FASC.siblings);}
badge.$s=$("<span>");
badge.$s.css({"font-size":"25%"}).text(" ");
badge.$r=$("<span>");
badge.$r.append(badge.$s);
FASC.badges[about.mode]=badge;}
$r=badge.$r.clone();
$i=badge.$i.clone();
$r.append($i).append(badge.$s.clone());
$i.hover(function(activity){
FASC.flip(activity,about,0,true);
return false;
},function(activity){
FASC.flip(activity,about,0,false);
return false;
});
$i.click(function(activity){
FASC.flip(activity,about,1);
return false;
});
about.$span=$r;
return $r;
};
FASC.$failure=function(anchor){
var $r=$("<span>"),$s=$("<span>");
$s.css({"white-space":"nowrap"});
$s.css({"font-size":"25%"});
$s.text(" ");
$r.append($s);
$s=$("<span>");
$s.addClass(FASC.single);
$s.css({"background-color":"#FFFF00",
"border":"#FF0000 2px solid",
"color":"#FF0000",
"font-size":"120%",
"font-weight":"bold",
"padding-left":"0.2em",
"padding-right":"0.2em"});
$s.attr({title:anchor});
$s.text("#");
$r.append($s);
$s=$("<span>");
$s.css({"font-size":"25%"});
$s.text(" ");
$r.append($s);
return $r;
};
FASC.family=function(all){
var r={},s,seek,$e;
for(s in all){
if(all[s]){
if(FASC.$content){
if(typeof FASC.reApos!=="object"){
FASC.reApos=new RegExp("'","g");}
seek="[id='"+s.substr(1).replace(FASC.reApos,"\\'")+"']";
try{
$e=FASC.$content.find(seek);
}catch(e){
$e=false;}
if($e&&$e.length&&!(FASC.$exclude&&FASC.$exclude.find(seek).length)){
r[s]=$e;}
}else{
r[s]=all[s];}}}
return r;
};
FASC.fiat=function(about,action){
var illusive=0.75,margin=10,options={align:"center",anchor:true,horizontalPosition:"center",padded:false,verticalPosition:"below"},show=about.sign,sign=FASC.sign+(action?"-t":"-i")+about.id,$p=$("<span>"),r;
$p.css({"left":(-0.5*about.$span.innerWidth()-1)+"px",
"position":"relative",
"top":"3px"});
about.$span.append($p);
options.$floatableContainer=$p;
$p=$("<span>");
if(show){
show=(action?"#":"")+FASC.cfg.escape(show);
}else{
show="#";}
if(about.mode===2){
$p.css({"background-color":"#FFFF00",
"color":"#FF0000",
"font-weight":"bold",
"margin":"0.2em",
"padding":"0.4em"}).text(show);
}else{
if(show){
if(action){
show=FASC.cfg.fancy(show);
illusive=0.95;}
$p.css({"color":"#000000",
"font-weight":"normal"}).text(show);
}else{
$p.css({"margin":"0.2em",
"width":"2em"}).text(" ");}}
$p.attr({"id":sign}).addClass(FASC.sign+"-text")
.css({"font-family":"sans-serif",
"font-size":"medium",
"font-style":"normal",
"font-variant":"normal",
"visibility":"hidden"});
FASC.$body.append($p);
$p=$("#"+sign);
options.width=$p.outerWidth()+margin;
$p.detach().css({"visibility":"visible"});
options.$content=$p;
r=new OO.ui.PopupWidget(options);
r.$floatable.attr({"role":"tooltip"}).css({"opacity":illusive,
"padding":"2px",
"text-align":"center"});
FASC.$body.append(r.$floatable);
return r;
};
FASC.file=function(anchor,alert,$a){
var sign=anchor.substr(1),lapse=(!FASC.fine(sign)),mode=(alert?1:(lapse?2:0)),id=FASC.bubbles.length,bubble={id:id,mode:mode,popups:[false,false],sign:sign,live:false,$a:$a,$span:false};
FASC.bubbles.push(bubble);
$a.attr({"title":null});
$a.before(FASC.$factory(bubble));
};
FASC.filter=function(anchor){
var r=true,i,s;
if(FASC.unStart){
for(i=0;i<FASC.unStart.length;i++){
s=FASC.unStart[i];
if(anchor.substr(1,s.length)===s){
r=false;
break;}}}
return r;
};
FASC.fine=function(anchor){
var r=true,i;
if(typeof FASC.reFine!=="object"){
FASC.reFine=[new RegExp("^\\s"),new RegExp("\\s$"),new RegExp("^\\d"),new RegExp("[<>'\"#%\\\\]"),new RegExp("\\?\\?")];}
for(i=0;i<FASC.reFine.length;i++){
if(FASC.reFine[i].test(anchor)){
r=false;
break;}}
return r;
};
FASC.fire=function(){
FASC.badges=[false,false,false];
if(typeof FASC.large!=="boolean"){
FASC.large=false;}
if(typeof FASC.unStart!=="object"){
FASC.unStart=false;}
FASC.reFine=false;
FASC.scope=FASC.sign+"-inner";
FASC.show=FASC.sign+"-mark";
FASC.single=FASC.show+" "+FASC.sign+"-broken";
$(FASC.cfg.fire);
};
FASC.flag=function(){
var $before=FASC.cfg.$flag(),dup,s,$box,$li,$ul;
if($before){
$box=$("<div>");
$ul=$("<ul>");
for(s in FASC.dup){
dup=FASC.dup[s];
$li=$("<li>");
$li.text(dup.length+"× "+s);
$ul.append($li);}
for(s in FASC.want){
$li=$("<li>");
$li.text("−"+FASC.want[s]+"× "+s);
$ul.append($li);}
$box.css({"border":"#FF0000 2px solid",
"color":"#FF0000",
"margin-bottom":"1em",
"margin-top":"1em",
"padding":"0.5em"});
$box.attr({"id":FASC.sign+"-errors"});
$box.addClass(FASC.show+" error "+FASC.sign+"-errors");
$box.append($ul);
$before.before($box);}
};
FASC.flip=function(activity,about,apply,activate){
var live=about.live,popup=about.popups[apply];
if(typeof activity==="object"&&activity){
if(typeof activity.preventDefault==="function"){
activity.preventDefault();}
if(typeof activity.stopPropagation==="function"){
activity.stopPropagation();}}
if(!popup){
popup=FASC.fiat(about,apply);
about.popups[apply]=popup;
if(apply&&!about.popups[0]){
about.popups[0]=FASC.fiat(about,0);}}
if(apply){
about.popups[0].toggle(false);
live=!live;
about.live=live;
popup.toggle(live);
}else if(live){
popup.toggle(false);
}else{
popup.toggle(activate);}
};
FASC.furnish=function(){
var total={},$total=$("[id]"),dup,i,lapsus,s,$e,$inner;
FASC.bubbles=[];
FASC.dup={};
FASC.total=[];
FASC.want=false;
$("."+FASC.show).remove();
for(i=0;i<$total.length;i++){
$e=$total.eq(i);
s="#"+$e.attr("id");
if(FASC.filter(s)){
if(FASC.cfg.familiar(s,$e)){
s=false;}
}else{
s=false;}
if(s){
if(typeof total[s]==="object"){
if(typeof FASC.dup[s]!=="object"){
FASC.dup[s]=[total[s]];
total[s]=null;}
FASC.dup[s].push($e);
}else{
total[s]=$e;}}}
$total=false;
if(typeof total["#"]==="object"){
FASC.dup["#"]=[total["#"]];
total["#"]=true;}
for(s in FASC.dup){
lapsus=true;
FASC.total.push(s);
dup=FASC.dup[s];
for(i=0;i<dup.length;i++){
$e=dup[i];
if($e){
FASC.file(s,true,$e);}}
total[s]=false;}
if(!lapsus){
FASC.dup=false;}
if(FASC.locked){
$inner=$("a[href^='#']");
for(i=0;i<$inner.length;i++){
$e=$inner.eq(i);
s=$e.attr("href");
if(s!=="#"){
$e.addClass(FASC.scope);
if(typeof total[s]!=="object"&&FASC.filter(s)){
$e.before(FASC.$failure(s));
if(!FASC.want){
FASC.want={};}
if(typeof FASC.want[s]==="number"){
FASC.want[s]=FASC.want[s]+1;
}else{
FASC.want[s]=1;}}}}}
if(FASC.dup||FASC.want){
FASC.flag();}
total=FASC.family(total);
for(s in total){
if(typeof total[s]==="object"){
FASC.total.push(s);
if(FASC.learn){
FASC.file(FASC.cfg.fair(s),false,total[s]);}}}
};
fire();
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>fragmentAnchors/r.js