Jump to content

User:PerfektesChaos/js/remindErrorMessages/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/remindErrorMessages/r.js
/// 2022-07-01 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#31E7A307#
/// @license:CC-by-sa/4.0 GPLv3
///<nowiki>
(function(mw,$){
"use strict";
var Version=2.6,Sign="remindErrorMessages",Shop="w:en:User:PerfektesChaos/js/",Selectors=[".mw-error",".mw-warning",".error",".warning",".errorbox",".warningbox",".cm-error","div[role=\"alert\"]"],Submit=".errorbox",Category={state:".mw-hidden-catlinks",submit:".hiddencats",track:["duplicate-args-category","expensive-parserfunction-category","graph-broken-category","kartographer-broken-category","math-tracking-category-error","math-tracking-category-render-error","node-count-exceeded-category","post-expand-template-argument-category","post-expand-template-inclusion-category","restricted-displaytitle-ignored","score-error-category","syntaxhighlight-error-category","templatestyles-page-error-category"],$hidden:false},CodeMirr={live:false},Content={$contentSub:false},Repo={minutes:1440},This={complaints:false,config:false,css:{bark:{"background-color":"#FFFF00",
"color":"#FF0000",
"font-size":"120%",
"font-weight":"bold"},
box:{"border-color":"#FF0000",
"border-style":"solid",
"border-width":"3px",
"font-size":"1rem",
"font-style":"normal",
"font-weight":"normal",
"line-height":"1.3rem",
"margin-top":"0.5rem",
"margin-bottom":"0.5rem",
"padding":"5px"},
preview:{"background-color":"#FFDDDD",
"border-color":"#FF0000",
"border-style":"dashed",
"border-width":"2px",
"font-size":"0.8rem",
"line-height":"1.5rem",
"margin-top":"1rem",
"margin-bottom":"1.5rem",
"padding-top":"0.3rem",
"padding-bottom":"0.3rem",
"padding-left":"1rem",
"padding-right":"1rem"},
warn:{"background-color":"#FF0000",
"color":"#FFFF00",
"font-size":"150%",
"font-weight":"1000",
"margin-left":"0.5em",
"margin-right":"0.5em",
"padding-left":"0.5em",
"padding-right":"0.5em",
"padding-top":"4px",
"padding-bottom":"4px"}
},options:{categories:"object",hiddencats:"boolean",maintCats:"number"},opt:false,shrink:"-invisible",suppress:"-noContent",unselect:["#editpage-copywarn-declaration","#mw-anon-preview-warning"],warnDrop:[".mw-warning-with-logexcerpt"]
};
Category.factory=function(){
if(typeof Category.track==="object"&&Category.track&&typeof Category.track.length==="number"){
if(typeof Category.Api==="undefined"){
Category.Api=new mw.Api();}
Category.Api.loadMessagesIfMissing(Category.track).done(Category.feed).fail(Category.fault);
}else{
Category.feed();}
};
Category.fault=function(jqXHR,textStatus,errorThrown){
var scream;
if(textStatus){
switch(typeof textStatus){
case "object":
if(typeof textStatus.textStatus==="string"){
scream=textStatus.textStatus;
}else{
scream="";}
if(typeof textStatus.exception==="string"&&textStatus.exception){
scream=scream+" ("+textStatus.exception+")";}
break;
case "string":
scream=textStatus;
break;}}
if(errorThrown){
if(scream){
scream=scream+"  -- Error: ";}
scream=scream+errorThrown;}
if(!scream){
scream="???";}
if(typeof window.console==="object"&&typeof window.console.log==="function"){
window.console.log(Sign+" * "+scream);
if(typeof textStatus==="object"&&textStatus&&typeof window.console.dir==="function"){
window.console.dir(textStatus);}}
};
Category.feed=function(answer){
var i,s;
Category.tracking=false;
Category.parsing=false;
if(answer){
for(i=0;i<Category.track.length;i++){
s=Category.track[i];
if(mw.messages.exists(s)){
s=mw.message(s).plain();
if(s.indexOf("\n")<0&&s.indexOf("{{")<0){
if(typeof Category.tracking!=="object"){
Category.tracking=[];}
Category.tracking.push(s);
if(typeof Category.titles!=="object"){
Category.titles={};}
Category.titles[s]=true;
}else{
if(typeof Category.parsing!=="object"){
Category.parsing=[];}
Category.parsing.push(s);}}}}
if(!Category.$hidden){
Category.fire();
Content.follow();}
Repo.flush();
};
Category.fetch=function(){
var repo=Repo.first(),load;
if(!repo||typeof repo.titles==="undefined"||typeof repo.parsing==="undefined"){
load=true;
}else{
Category.titles=repo.titles;
Category.parsing=repo.parsing;
Category.fire();
Content.follow();
load=!Repo.fresh();}
if(load){
mw.loader.using(["mediawiki.api"],Category.factory);}
};
Category.filter=function($a){
var c,i,re,r,seek=$a.text();
if(typeof Category.titles==="object"&&Category.titles&&typeof Category.titles[seek]==="boolean"){
r=true;
}else if(typeof Category.parsing==="object"&&Category.parsing&&typeof Category.parsing.length==="number"){
re=new RegExp("\\b"+seek+"\\b");
for(i=0;i<Category.parsing.length;i++){
if(re.test(Category.parsing[i])){
r=true;
break;}}}
if(!r&&Category.user){
for(i=0;i<Category.user.length;i++){
c=Category.user[i];
switch(typeof c){
case "string":
r=(c===seek);
break;
case "object":
case "function":
r=c.test(seek);
break;}
if(r){
break;}}}
return(r?$a.clone():false);
};
Category.fire=function(){
var $wrap=$(Category.state),i,k,less,s,$div,$e,$li,$list,$ul;
if($wrap.length){
$e=$wrap.find("ul");
if($e.length){
$list=$e;
$e=$wrap.contents();
if($e.get(0).nodeType===3){
$div=$("<div>");
$div.text($e.eq(0).text().trim());}}
}else{
$wrap=$(Category.submit);
if($wrap.length){
$e=$wrap.find("p");
if($e.length){
$div=$("<div>");
$div.text($e.text().trim());}
$list=$wrap.find("ul");
less=true;}}
if($div){
$list=$list.children();
for(i=0;i<$list.length;i++){
$e=$list.eq(i).find("a");
if($e.length){
if(Category.limit){
$e=Category.filter($e);
}else{
$e=$e.clone();}
if($e){
$e.attr({target:"maintCats"});
if(less){
s=$e.text().trim();
k=s.indexOf(":");
if(k>0){
s=s.substr(k+1);
$e.text(s);}}
$li=$("<li>");
$li.append($e);
$ul=$ul||$("<ul>");
$ul.append($li);}}}
if($ul){
Category.$hidden=$("<div>");
Category.$hidden.append($div);
Category.$hidden.append($ul);}}
};
CodeMirr.fiat=function(){
var i,learnt,$e,$errors,$li;
if(CodeMirr.cm){
$errors=CodeMirr.$wrapper.find(".cm-error");
if($errors.length){
if(!CodeMirr.complaints){
CodeMirr.complaints=[];
CodeMirr.many=0;}
for(i=0;i<$errors.length;i++){
$e=$errors.eq(i);
if(!$e.attr("id")){
learnt=true;
CodeMirr.many++;
$e.attr("id","cm-error-"+CodeMirr.many);}}
if(learnt||$errors.length!==CodeMirr.complaints.length){
CodeMirr.complaints=[];
for(i=0;i<$errors.length;i++){
$e=$errors.eq(i);
$li=$("<li>");
$li.attr("id",$e.attr("id"));
CodeMirr.complaints.push($li);}}}}
};
CodeMirr.finish=function(){
CodeMirr.cm=null;
};
CodeMirr.fire=function(application){
CodeMirr.cm=application;
if(!CodeMirr.live){
CodeMirr.live=true;
mw.hook("CodeMirr.disabled").add(CodeMirr.finish);
CodeMirr.complaints=false;}
CodeMirr.$wrapper=$(CodeMirr.cm.getWrapperElement());
CodeMirr.cm.on("change",CodeMirr.fiat);
};
CodeMirr.first=function(){
var r,uo;
if(!CodeMirr.cm&&typeof window.CodeMirror==="function"&&typeof window.CodeMirr.doc==="object"){
CodeMirr.cm=window.CodeMirror;}
if(CodeMirr.cm){
uo=mw.user.options.get("usecodemirror");
if(typeof uo==="number"&&uo>0){
r=CodeMirr.cm;}}
return r;
};
Content.fine=function(){
if(This.lapsus){
This.$box.hide();
if(typeof This.$barWarn==="object"){
This.$barWarn.hide();}
This.lapsus=false;}
};
Content.flip=function(as,alert){
var $e=$(alert),show,sign,$a;
if(!$e.hasClass(This.signed)&&!$e.hasClass(This.suppress)){
sign=$e.attr("id");
if(!sign){
sign=Sign+"_"+as;
$e.attr({id:sign});}
$e.addClass(This.signed).css(This.css.bark);
show=$e.text().replace(/^(\s|\xA0|&#160;)+/,"")
.replace(/(\s|\xA0|&#160;)+$/,"");
if(!show){
show="["+as+"]";
$e.text("ERROR"+show);}
$e.find("a").css({"text-decoration":"underline"});
$a=$("<a>").attr({href:"#"+sign}).text(show);
This.complaints.push($("<li>").append($a));
$e.parent().show();
$e.find(Content.selector).addClass(This.signed);}
return true;
};
Content.flop=function($alerts){
var sign=Sign+"_box",swift="#"+sign,view={"display":null,
"visibility":"visible"},
$box=$(swift),i,$next;
if($alerts||Category.$hidden||$box.length){
if($box.length){
This.$ul.empty();
This.$box=$box;
This.$box.show();
}else{
This.$box=$("<div>");
This.$box.attr("id",sign);
if(This.opts){
if(typeof This.opts.barkCSS==="object"){
$.extend(This.css.bark,This.opts.barkCSS);}
if(typeof This.opts.boxCSS==="object"){
$.extend(This.css.box,This.opts.boxCSS);}}
This.$box.css(This.css.box);
This.$ul=$("<ul>");
This.$box.append(This.$ul);
Content.$content.prepend(This.$box);}
}else{
$(Submit).eq(0).attr({id:sign});}
if(This.action==="submit"){
if(typeof This.$barWarn==="object"){
This.$barWarn.show();
}else{
$next=$("#wpPreview");
if($next.length){
This.$barWarn=$("<a>");
This.$barWarn.attr({href:swift,id:Sign+"_attention"});
if(This.opts&&typeof This.opts.barCSS==="object"){
$.extend(This.css.warn,This.opts.barCSS);}
This.$barWarn.css(This.css.warn);
This.$barWarn.text("!");
$next.before(This.$barWarn);}}}
if($alerts){
This.complaints=[];
$alerts.each(Content.flip);
for(i=0;i<Selectors.length;i++){
view.display="block";
$("div"+Selectors[i]).css(view);
view.display="inline";
$("span"+Selectors[i]).css(view);}
$(This.shrink).empty();}
if(Category.$hidden){
This.complaints=This.complaints||[];
This.complaints.push(Category.$hidden);}
This.lapsus=(This.complaints.length);
if(This.lapsus){
for(i=0;i<This.complaints.length;i++){
This.$ul.append(This.complaints[i]);}}
};
Content.follow=function(){
mw.hook("wikipage.content").add(Content.fresh);
mw.hook("error.message").add(Content.fresh);
mw.hook(Sign+".refresh").add(Content.fresh);
};
Content.fresh=function($area){
var $warnings=$(Content.selector).not(Content.unselect),i,suppress,$old,$paras,$preview,$warningbox;
if(!Content.$contentSub){
if(Content.$contentSub===false){
Content.$contentSub=$("#contentSub");
if(Content.$contentSub.length){
Content.$content=Content.$contentSub;
}else{
Content.$contentSub=null;}}
if(!Content.$contentSub){
if($area){
Content.$content=$area;
}else{
Content.$content=$("#mw-content-text");}}}
if($warnings.length){
$warningbox=$(".warningbox");
if($warningbox.length){
$preview=$(".previewnote .warningbox");
if($preview.length){
if(This.opts&&typeof This.opts.previewCSS==="object"){
$.extend(This.css.preview,This.opts.previewCSS);}
$preview.removeClass("warningbox "+This.signed).css(This.css.preview);
$warnings=$warnings.not($preview.get(0));
$paras=$preview.find("p");
if($paras.length>1){
$preview=$paras.eq(0);
$paras=$paras.not($preview);
$paras.each(function(){
var $p=$(this);
$warnings=$warnings.add($p);
$p.detach();
});}}
$old=$warningbox.filter(".mw-revision");
if($old.length){
$old.addClass(This.suppress);
$warnings=$warnings.not($old);
$old=$area.children().eq(0).filter(".warningbox");
if($old.length){
$old.addClass(This.suppress);
$warnings=$warnings.not($old);}}
if(This.warnDrop.length){
for(i=0;i<This.warnDrop.length;i++){
if(i){
suppress=suppress+",";
}else{
suppress="";}
suppress=suppress+This.warnDrop[i];}
$old=$warningbox.filter(suppress);
if($old.length){
$old.addClass(This.suppress);
$warnings=$warnings.not($old);}}}}
if($warnings.length){
Content.flop($warnings);
}else if($(Submit).length||Category.$hidden){
Content.flop();
}else{
Content.fine();}
};
Repo.first=function(){
var stored=mw.storage.get(Sign);
if(stored){
try{
Repo.repo=JSON.parse(stored);
}catch(ex){
Repo.repo=false;}}
return Repo.repo;
};
Repo.flush=function(){
var date=new Date(),ms=date.getTime(),luck;
Repo.repo={minutes:Math.floor(ms*0.0000166666667)};
if(typeof Category.titles==="object"){
Repo.repo.titles=Category.titles;
}else{
Repo.repo.titles=false;}
if(typeof Category.parsing==="object"){
Repo.repo.parsing=Category.parsing;
}else{
Repo.repo.parsing=false;}
luck=mw.storage.set(Sign,JSON.stringify(Repo.repo));
if(!luck){
Category.fault(false,"local storage dump");}
};
Repo.fresh=function(){
var date,m,r;
if(typeof Repo.repo==="object"&&Repo.repo&&typeof Repo.repo.minutes==="number"&&typeof Repo.minutes==="number"){
date=new Date();
m=date.getTime()*0.0000166666667;
r=(m<Repo.repo.minutes+Repo.minutes);}
return r;
};
function feature(all,apply,about){
if(typeof all[apply]===about&&(all[apply]||all[apply]===false)){
This.opts[apply]=all[apply];}}
function features(assign){
var s;
if(typeof assign==="object"&&assign){
This.opts=This.opts||{};
for(s in This.css){
This.options[s+"CSS"]="object";}
for(s in assign){
feature(assign,s,This.options[s]);}}}
function fiat(){
var i,v;
if(This.namespaceNumber!==14){
This.opts=This.opts||{};
if(typeof This.opts.maintCats!=="number"&&typeof This.opts.hiddencats==="boolean"){
if(This.opts.hiddencats){
This.opts.maintCats=2;
}else{
This.opts.maintCats=0;}}
if(typeof This.opts.categories==="object"&&typeof This.opts.categories.length==="number"&&This.opts.categories.length>=1){
Category.user=[];
for(i=0;i<This.opts.categories.length;i++){
v=This.opts.categories[i];
if((typeof v==="string"&&v)||((typeof v==="object"&&v||typeof v==="function")&&typeof v.test==="function")){
Category.user.push(v);}}
if(!Category.user.length){
Category.user=false;}
}else{
Category.user=false;}
if(typeof This.opts.maintCats!=="number"){
This.opts.maintCats=1;}
if(This.opts.maintCats>=1){
Category.limit=(This.opts.maintCats<2);}
if(Category.limit){
mw.loader.using(["mediawiki.storage"],Category.fetch);
}else{
if(This.opts.maintCats>=2){
Category.fire();}
Content.follow();}
}else{
Content.follow();}}
function fire(){
var card={type:Sign,vsn:Version,doc:"[["+Shop+Sign+"]]"};
This.lapsus=false;
if(typeof mw.libs[Sign]==="object"&&mw.libs[Sign]){
This.config=mw.libs[Sign];
if(This.config){
This.config.vsn=card.vsn;
This.config.doc=card.doc;
if(typeof This.config.options==="object"&&This.config.options){
features(This.config.options);}}}
This.complaints=[];
$(fiat);
mw.hook(Sign).fire(card);}
function first(){
var signature="ext.gadget."+Sign,env,i,launch,rls;
if(mw.loader.getState(signature)!=="ready"){
rls={};
rls[signature]="ready";
mw.loader.state(rls);
mw.hook(Sign+"-options").add(features);
env=mw.config.get(["wgAction","wgNamespaceNumber"]);
switch(env.wgAction){
case "view":
launch=(env.wgNamespaceNumber>=0);
break;
case "submit":
case "parsermigration-edit":
launch=true;
break;}
if(launch){
This.action=env.wgAction;
This.namespaceNumber=env.wgNamespaceNumber;
for(i=0;i<Selectors.length;i++){
if(i){
Content.selector=Content.selector+",";
}else{
Content.selector="";}
Content.selector=Content.selector+Selectors[i];}
for(i=0;i<This.unselect.length;i++){
if(i){
Content.unselect=Content.unselect+",";
}else{
Content.unselect="";}
Content.unselect=Content.unselect+This.unselect[i];}
This.signed=Sign+"_msg";
This.shrink="."+Sign+This.shrink;
This.suppress=Sign+This.suppress;
mw.loader.using(["user"],fire);}}}
first();
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>remindErrorMessages/r.js