User:PerfektesChaos/js/localEdit/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/localEdit/r. |
/// User:PerfektesChaos/js/localEdit/r.js
/// 2018-08-24 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#35C19827#
/// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA)
///<nowiki>
(function(mw,$){
"use strict";
var vsn=0.3,WLE;
if(typeof mw.libs.localEdit!=="object"||!mw.libs.localEdit){
mw.libs.localEdit={};}
WLE=mw.libs.localEdit;
WLE.vsn=vsn;
WLE.type="localEdit";
WLE.scan="*.txt; *.text; *.wiki";
WLE.suffix="txt";
if(!WLE.lang){
WLE.lang={};}
if(!WLE.pageImport){
WLE.pageImport={};}
if(typeof WLE.debugging!=="object"){
WLE.debugging={loud:true,say:"localEdit"};}
WLE.lang.texts={
"BrowserType":{"en":"Browser type",
"de":"Browser-Typ"},
"AddOn":{"en":"Add-on",
"de":"Add-On"},
"ConfirmLosses":{"en":"Really loose edits?",
"de":"Wirklich Änderungen verlieren?"},
"DirBase":{"en":"Base directory (local)",
"de":"Stammverzeichnis (lokal)"},
"DirSub":{"en":"Sub directory for project",
"de":"Unterverzeichnis für Projekt"},
"Edit":{"en":"Start editing local file",
"de":"Bearbeitung lokaler Dateien beginnen"},
"FileExtFilter":{"en":"File extensions (Filter)",
"de":"Datei-Erweiterungen (Filter)"},
"FileExtNew":{"en":"File extension (create)",
"de":"Datei-Erweiterung (Neuanlage)"},
"HeadlineConfig":{"en":"Personal options",
"de":"Persönliche Einstellungen"},
"ImportPage":{"en":"Import from page",
"de":"Seitentext importieren"},
"ImportPageAbort":{"en":"Abort",
"de":"Abbrechen"},
"ImportPageClear":{"en":"Empty edit area first",
"de":"Erst Bearbeitungsfeld leeren"},
"ImportPageFire":{"en":"Import",
"de":"Importieren"},
"installed-false":{"en":"Not active",
"de":"Nicht aktiv"},
"installed-true":{"en":"Active",
"de":"Aktiviert"},
"NamePage":{"en":"Page name:",
"de":"Seitenname:"},
"OldID":{"en":"Optional revision",
"de":"Optional/alternativ Version"},
"OpenFile":{"en":"Open file",
"de":"Datei öffnen"},
"SaveFile":{"en":"Save file",
"de":"Datei speichern"},
"SaveFileAs":{"en":"Save file as",
"de":"Datei speichern unter"},
"URLform":{"en":"URL format",
"de":"URL-Format"},
"URLformfix":{"en":"Fix it",
"de":"Verbessern"}
};
WLE.lang.trans={
"de":"de",
"de-at":"de",
"de-ch":"de",
"de-formal":"de",
"als":"de",
"bar":"de",
"dsb":"de",
"frr":"de",
"gsw":"de",
"hsb":"de",
"ksh":"de",
"lb":"de",
"nds":"de",
"pdc":"de",
"pdt":"de",
"pfl":"de",
"sli":"de",
"stq":"de",
"vmf":"de"
};
WLE.pageImport.fault=function(){
WLE.pageImport.flop();
};
WLE.lang.favorite=function(){
var s;
if(!this.slang){
s=mw.config.get("wgUserLanguage").toLowerCase();
s=this.trans[s];
if(s){
this.slang=s;
}else{
this.slang="en";}}
};
WLE.lang.feature=function(apply){
var e,r;
if(!this.slang){
this.favorite();}
e=this.texts[apply];
if(e){
r=e[this.slang];
if(!r){
r=e.en;
if(!r){
r="???"+apply+"???";}}
}else{
r="***"+apply+"***";}
return r;
};
WLE.pageImport.fiat=function(){
this.$throbber.attr("style","display:block;float:right;");
mw.loader.using(["mediawiki.api"],this.find);
};
WLE.pageImport.fill=function(){
var g,l=true,s=WLE.pageImport.$name.val();
if(!WLE.reTrim){
WLE.reTrim=new RegExp("^[ \t]*(.+[^ \t])?[ \t]*$","");}
if(s){
g=WLE.reTrim.exec(s);
if(g){
s=g[1];
WLE.pageImport.$name.val(s);
l=false;}}
s=WLE.pageImport.$vsn.val();
if(s){
g=WLE.reTrim.exec(s);
if(g){
s=g[1];
WLE.pageImport.$vsn.val(s);
if(!WLE.reNum){
WLE.reNum=new RegExp("^[1-9][0-9]*$","");}
l=(!WLE.reNum.test(s));}}
WLE.pageImport.$fire.prop("disabled",l);
};
WLE.pageImport.find=function(){
var q=new mw.Api(),s=WLE.pageImport.$vsn.val(),w={action:"query",prop:"revisions",rvlimit:"1",rvprop:"content"};
if(s){
w.revids=s;
}else{
if(!WLE.pageImport.reSpU){
WLE.pageImport.reSpU=new RegExp(" ","g");}
s=WLE.pageImport.$name.val();
s=s.replace(WLE.pageImport.reSpU,"_");
w.titles=s;}
q.get(w).done(WLE.pageImport.found).fail(WLE.pageImport.fault);
};
WLE.pageImport.found=function(arrived){
var pid,q=(typeof arrived==="object");
if(q){
q=arrived.query;
if(q){
q=q.pages;
if(q){
for(pid in q){
q=q[pid];
if(q){
WLE.feed(q.revisions[0]["*"]);
WLE.suggest=q.title;}
break;}}}}
WLE.pageImport.flop();
};
WLE.pageImport.flop=function(){
this.$div.attr("style","display:none");
};
WLE.pageImport.form=function(){
var launch=true,s=WLE.feed(false);
if(s){
if(!WLE.reWS){
WLE.reWS=new RegExp("[^ \t\n]","");}
launch=(!WLE.reWS.test(s));}
if(launch){
this.$div=WLE.$editform.find("#LocalEditPageImportDiv");
if(this.$div.length){
this.$form=this.$div.find("#LocalEditPageImportForm");
if(!this.$form.length){
s="<span id='LocalEditPageImportForm'><label for='pageImportName'>"+WLE.lang.feature("NamePage")+"</label> <input name='pageImportName' id='pageImportName' type='text' size='66' /> "+WLE.forward("ImportPageFire",false)+"<br /><label for='pageImportVsn'>"+WLE.lang.feature("OldID")+"</label> <code>oldid=</code> <input name='pageImportVsn' type='text' size='15' /><br />"+WLE.forward("ImportPageAbort",true)+"</span>";
this.$form=$(s);
this.$div.append(this.$form);
s="//upload.wikimedia.org/wikipedia/commons/d/de/Ajax-loader.gif";
s="<img name='pageImportThrobber' src='"+s+"' />";
this.$throbber=$(s);
this.$div.prepend(this.$throbber);
this.$name=this.$form.find("#pageImportName");
this.$name.mouseleave(this.fill);
this.$name.blur(this.fill);
this.$vsn=this.$form.find("#pageImportVsn");
this.$vsn.mouseleave(this.fill);
this.$vsn.blur(this.fill);
this.$fire=this.$div.find("#WLE_select_ImportPageFire");}
this.$form.attr("style","display:block");
this.$throbber.attr("style","display:none");
this.$div.attr("style","border: solid 3px #0000FF;padding: 0.4em;");
this.fill();}
}else{
window.alert(WLE.lang.feature("ImportPageClear"));}
};
WLE.face=function(){
var icon=-1,s,scan="",start="",suffix="",system="",$div,$edit,$table;
WLE.flat(false);
$div=$("<div id='LocalEditDiv' />");
WLE.first($div);
if($.client){
system=$.client.profile().layout;
if("gecko".indexOf(system)>=0){
icon=1;}}
if(WLE.opt&&typeof WLE.opt==="object"){
if(typeof WLE.opt.scan==="string"){
WLE.scan=WLE.opt.scan;}
if(typeof WLE.opt.suffix==="string"){
WLE.suffix=WLE.opt.suffix;}}
$edit=$(window.document).find("#ca-edit");
if($edit.length){
$edit=$edit.find("a");
if($edit.length){
start=$edit.attr("href");
if(start){
start=start.replace(/\x27/g,"'")
.replace(/</g,"<");
start="<a class='WLE.buttons' id='WLE.startEdit' style='display:none' href='"+start+"'>"+WLE.lang.feature("Edit")+"</a>";}}}
WLE.specific=mw.config.get("wgDBname")+"."+mw.config.get("wgUserName");
s="<table id='LocalEditTable' class='wikitable'>\n<caption>LocalEdit "+WLE.vsn+"</caption>\n<tbody>\n<tr>\n<td>"+WLE.lang.feature("BrowserType")+"</td>\n<td>"+system+"</td>\n<td>"+WLE.factory(icon,"WLE.client")+"</td>\n</tr>\n<tr>\n<td>"+WLE.lang.feature("URLform")+"</td>\n<td>"+WLE.fix(false)+"</td>\n<td>"+WLE.factory(WLE.fix(true),"WLE.URL")+"</td>\n</tr>\n<tr>\n<td>"+WLE.lang.feature("AddOn")+"</td>\n<td><span id='WLE.inactive'>"+WLE.lang.feature("installed-false")+"</span><span id='WLE.active' style='display:none'>"+WLE.lang.feature("installed-true")+"</span></td>\n<td>"+WLE.factory(-1,"WLE.stateIMG")+"</td>\n</tr>\n<tr>\n<th colspan='3'>"+WLE.lang.feature("HeadlineConfig")+"</th>\n</tr>\n<tr>\n<td>"+WLE.lang.feature("DirBase")+"</td>\n<td><span id='WLE.dirbase'></span></td>\n<td>"+WLE.folder("DirBase")+"</td>\n</tr>\n<tr>\n<td>"+WLE.lang.feature("DirSub")+"</td>\n<td><span id='WLE.specific' style='display:none'>"+WLE.specific+"</span><span id='WLE.dirsub' /></td>\n<td>"+WLE.folder("DirSub")+"</td>\n</tr>\n<tr>\n<td>"+WLE.lang.feature("FileExtFilter")+"</td>\n<td><span id='WLE.filextScan'>"+scan+"</span></td>\n<td> </td>\n</tr>\n<tr>\n<td>"+WLE.lang.feature("FileExtNew")+"</td>\n<td><span id='WLE.filextNew'>"+suffix+"</span></td>\n<td> </td>\n</tr>\n<tr>\n<th colspan='2'>"+start+"</th>\n</tr>\n</tbody>\n</table>";
$table=$(s);
$div.prepend($table);
};
WLE.factory=function(access,assign){
var pictures=[["Red_x","ba"],["Neutral","bd"],["Yes_check","fb"]],picture=pictures[access+1],symbol=picture[0],sucks=picture[1];
return "<img src='//upload.wikimedia.org/wikipedia/commons/thumb/"+sucks.substr(0,1)+"/"+sucks+"/"+symbol+".svg/16px-"+symbol+".svg.png' id='"+assign+"' />";
};
WLE.feed=function(apply){
var r=false;
if(this.$textarea){
if(typeof apply==="string"){
this.$textarea.val(apply);
r=apply;}
if(this.wikEd()&&window.wikEd.turnedOn&&window.wikEd.useWikEd&&window.wikEd.UpdateFrame&&window.wikEd.UpdateTextarea){
if(apply){
window.wikEd.UpdateFrame();
}else{
window.wikEd.UpdateTextarea();}}
if(!apply){
r=this.$textarea.val();
this.suggest=false;}}
return r;
};
WLE.fetch=function(action,add){
var i,n,elemt=window.document.getElementById("LocalEditDiv"),event=window.document.createEvent("Events");
event.initEvent("wikilocaleditButton",true,false);
elemt.setAttribute("action",action);
if(add){
n=add.length;
for(i=0;i<n;i++){
elemt.setAttribute(add[i][0],add[i][1]);}}
elemt.dispatchEvent(event);
};
WLE.filled=function(){
WLE.feed(true);
};
WLE.fire=function(){
var s=mw.config.get("wgAction");
switch(s){
case "view":
mw.loader.using(["user","mediawiki.user","mediawiki.util","jquery.client"],WLE.face);
break;
case "edit":
case "submit":
WLE.form(s);
window.document.addEventListener("wikilocaleditFilled",WLE.filled,true);
break;}
};
WLE.fired=function(action){
var cb,low,plus=[];
switch(action){
case "ImportPage":
WLE.pageImport.form();
break;
case "ImportPageAbort":
WLE.pageImport.flop();
break;
case "ImportPageFire":
WLE.pageImport.fiat();
break;
case "OpenFile":
WLE.feed(false);
low=false;
cb=mw.util.$content.find("#ANSI");
if(cb.length){
low=cb.prop("checked");}
plus.push(["lowcode",low]);
case "SaveFileAs":
if(WLE.scan){
plus.push(["scan",WLE.scan]);}
if(WLE.suffix){
plus.push(["suffix",WLE.suffix]);}
if(WLE.suggest){
plus.push(["suggest",WLE.suggest]);}
case "DirSub":
if(!WLE.specific){
WLE.specific=mw.config.get("wgDBname")+"."+mw.config.get("wgUserName");}
plus.push(["specific",WLE.specific]);
case "Abort":
case "SaveFile":
switch(action){
case "Abort":
case "SaveFile":
case "SaveFileAs":
WLE.feed(false);
break;}
break;}
if(!plus.length){
plus=false;}
WLE.fetch(action,plus);
};
WLE.first=function($assign){
this.$top=$("#mw-content-text");
if(this.$top.length){
this.$top.prepend($assign);
}else{
this.$top=$("#bodyContent");
if(!this.$top.length){
this.$top=$("#article");
if(!this.$top.length){
this.$top=$("#content");
if(!this.$top.length){
this.$top=mw.util.$content;}}}
this.$top.before($assign);}
};
WLE.fix=function(aim){
var r;
if(aim){
r=this.iconURL;
}else if(window.location.pathname.substr(0,6)==="/wiki/"){
this.iconURL=1;
r=" ";
}else{
this.iconURL=-1;
r="<a href='"+mw.util.getUrl(mw.config.get("wgPageName"))+"'>"+this.lang.feature("URLformfix")+"</a>";}
return r;
};
WLE.flat=function(after){
var s=".cn-fundraiser-banner,#mw-js-message,#siteNotice,#fundraising\n#ca-nstab-user,#ca-edit,#ca-view,#ca-history,#ca-move,.noarticletext,#newarticletext\n{display: none ! important;}";
if(after){
s=".editOptions\n{margin-top: 10px;"+(this.wikEd()?"background-color: transparent;":"")+" margin-bottom: 10px;}#editnotice-ns-2,.previewnote,\nDIV.mw-tos-summary,SPAN#wpSummaryLabel,DIV#editpage-copywarn,A#mw-editform-cancel,.editHelp,A[target=\"helpwindow\"],\nINPUT#wpDiff,INPUT#wpSave,INPUT#wpSummary,.editCheckboxes,.cancelLink,#enhanced-diff-live-button,#wikEdEditHelp,#wikEdLocalDiff,#wikEdSummaryInputWrapper,#thresholdSave,\n"+s;}
mw.util.addCSS(s);
};
WLE.folder=function(action){
var show="<span style='font-size: 200%; font-weight: bold;'>*</span>";
return "<div class='WLE.buttons' id='WLE."+action+"' style='display:none'>"+this.force(action,show,true)+"</div>";
};
WLE.force=function(action,assign,able){
return "<button type='button' id='WLE_select_"+action+"' style='background-color: #80FFFF' onclick='mw.libs.localEdit.fired(\""+action+"\")'"+(able?"":" disabled")+">"+assign+"</button>";
};
WLE.form=function(action){
var s,$elt,$form,$h1,$ta;
this.flat(true);
$form=mw.util.$content.find("#editform");
if($form.length){
$ta=$form.find("#wpTextbox1");
if($ta.length){
if(!$ta.attr("readonly")){
this.$editform=$form;
this.$textarea=$ta;
if(action==="edit"){
$ta.text("");}
$elt=$form.find("#wpPreview");
if($elt.length){
s="<span id='LocalEditDiv' style='border: solid 3px #0000FF; margin-left: 5px; padding: 0.4em;'>\nANSI:<input type='checkbox' name='ANSI' id='ANSI' />"+WLE.forward("OpenFile",true)+WLE.forward("ImportPage",true)+WLE.forward("SaveFile",false)+WLE.forward("SaveFileAs",true)+"</span><div id='LocalEditPageImportDiv' style='display:none' />";
$elt.after($(s));}}}}
$h1=mw.util.$content.find("#firstHeading");
if($h1.length){
$h1.text(this.wgTitle);
$h1.css("border","solid 2px #0000FF");
$h1.css("text-align","center");
$h1.css("background-color","#D0FFFF");}
s="<div id='LocalEditFileDiv'><span id='LocalEditFilePath' style='background-color: #D0FFFF;' /></div>";
this.first($(s));
};
WLE.forward=function(action,able){
return this.force(action,this.lang.feature(action),able);
};
WLE.wikEd=function(){
return(window.wikEd&&typeof window.wikEd==="object"&&!window.wikEd.disabled);
};
if(!WLE.loaded){
WLE.loaded=true;
if(mw.config.get("wgNamespaceNumber")===2){
WLE.wgTitle=mw.config.get("wgTitle");
if(WLE.wgTitle===mw.config.get("wgUserName")+"/LocalEdit"){
$(WLE.fire);}}
mw.loader.state({"ext.gadget.localEdit":"ready"});}
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>/localEdit/r.js