User:PerfektesChaos/js/loadResourceFile/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/loadResourceFile/r. |
/// User:PerfektesChaos/js/loadResourceFile/r.js
/// 2018-09-03 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#B32DF193#
/// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA)
///<nowiki>
(function(mw,$){
"use strict";
var VSN=1.6,LRF="loadResourceFile",basics,config,gui,lang,prego;
if(typeof mw.libs[LRF]!=="object"||!mw.libs[LRF]){
mw.libs[LRF]={};}
mw.libs[LRF].type=LRF;
LRF=mw.libs[LRF];
if(LRF.loaded){
return;}
basics={};
config={support:"User:PerfektesChaos/js/"+LRF.type};
gui={};
lang={};
LRF.doc="[[w:en:"+config.support+"]]";
LRF.vsn=VSN;
lang.texts={
"show":{"en":"Load CSS/JS file",
"de":"Lade CSS/JS-Datei"},
"sucks":{"en":"Local folder not yet defined",
"de":"Lokales Verzeichnis noch nicht definiert"},
"^show":{"en":"Load-Resource-File",
"de":"Load-Resource-File"},
"^suffix":{"en":"– Load local resource (CSS, JavaScript) files into current page.",
"de":"– Lade lokale Dateien mit CSS oder JavaScript in die aktuelle Seite"},
"^^charset":{"en":"Character encoding",
"de":"Zeichenkodierung"},
"^^charset+":{"en":"utf-8 (default), iso-8859-1",
"de":"utf-8 (Vorgabe), iso-8859-1"},
"^^path":{"en":"Local directory path",
"de":"Lokales Verzeichnis"},
"^^path+":{"en":"<div>Store on Wiki server<br />"+" (invisible for other users)</div>",
"de":"<div>Speichern auf dem Wiki-Server<br /> (unsichtbar für andere Benutzer)</div>"},
"^^portlet":{"en":"Create portlet link",
"de":"Portlet-Link einfügen"},
"^^portlet+":{"en":"<div style='margin-left:3em'>"+"Space sparated list"+" of canonical specialpage names<br />"+"Empty list:"+" all supported pages<br />"+"<code>0</code> –"+" Do not create portlet link.</>",
"de":"<div style='margin-left:3em'>Leerzeichen-getrennte Liste von kanonischen Namen<br />Leere Liste: Immer Portlet-Link<br /><code>0</code> – keine Portlet-Links</div>"}
};
lang.user={
"de":"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"
};
function bbLoadFile(app,doc,$){
var later=false;
function file(absolute,accept,asyncInhibit){
var o,s=absolute.toLowerCase();
if($){
if(s.slice(-3)===".js"){
o={"src":"file:/"+absolute,
"type":"text/javascript"
};
if(accept){
o.charset=accept;}
if(!(later||asyncInhibit)){
o.async="async";}
s=(later?"body":"head");
$(s).append($("<script />",o));
}else if(s.slice(-4)===".css"){
o={"href":"file:/"+absolute,
"rel":"stylesheet",
"type":"text/css"
};
if(accept){
o.charset=accept;}
$("head").append($("<link />",o));}
}else if(doc){
}}
app.files=function(apply,access,accept){
var i,s=typeof apply,set,start;
if(typeof access==="string"){
start=access;
}else if(this.storage){
start=this.storage;
}else{
start="/";}
if(start.search(/\/$/)<0){
start=start+"/";}
if(typeof accept==="string"){
set=accept;
}else if(this.set){
set=this.set;
}else{
set=false;}
if(s==="string"){
file(start+apply,set);
}else if(s==="object"){
if($.isArray(apply)){
for(i=0;i<apply.length;i++){
s=apply[i];
if(typeof s==="string"){
file(start+s,set);}}}}
};
function finished(){
later=true;}
app.folder=function(access){
if(typeof access==="string"){
this.storage=access;}
};
app.font=function(accept){
if(typeof accept==="string"){
this.set=accept;}
};
$(finished);
app.low=true;}
function fire(){
var rls;
if(!basics.low){
bbLoadFile(basics,null,$);}
if(typeof LRF.set==="string"){
config.foreign(LRF.set);}
config.fetch();
gui.portlet=LRF.portlet;
if(gui.portlet===undefined||gui.portlet===true){
gui.portlet={};}
if(typeof config.lazy==="boolean"&&!config.lazy){
gui.portlet=false;}
if(gui.portlet&&typeof gui.portlet==="object"){
$(gui.factory);}
if(mw.config.get("wgCanonicalSpecialPageName")==="Gadgets"&&prego){
config.form();}
rls={};
rls["ext.gadget."+LRF.type]="ready";
mw.loader.state(rls);
if(typeof LRF.afterLoad==="function"){
LRF.afterLoad();}}
config.favorite=function(){
var r;
lang.favorite();
switch(lang.slang){
case "de":
r="de.wikipedia.org";
break;
default:
r="wiki.riteme.site";}
return "//"+r+"/wiki/"+this.support;
};
config.fetch=function(){
var vals;
prego=mw.libs[this.supply];
if(prego){
vals=prego.fetch(LRF.type);
if(vals&&typeof vals==="object"){
if(typeof vals.charset==="string"){
vals.charset=$.trim(vals.charset);
if(vals.charset!==""){
config.foreign(vals.charset);}}
if(typeof vals.path==="string"){
this.stored=$.trim(vals.path);
if(this.stored===""){
this.stored=false;}}
if(typeof vals.portlet==="boolean"){
config.lazy=vals.portlet;}}}
};
config.filled=function(assigned){
if(typeof assigned==="object"&&assigned){
if(typeof assigned.path==="string"){
config.folder(assigned.path);}}
};
config.filter=function(access){
var r=false;
if(typeof access==="string"){
r=$.trim(access).replace(/\\/g,"/");
if(r===""){
r=false;}}
if(!r){
r=this.folder();}
return r;
};
config.fire=function(){
var rls,signature;
this.supply="preferencesGadgetOptions";
signature="ext.gadget."+this.supply;
if(!mw.loader.getState(signature)){
rls={};
rls[signature]="loading";
mw.loader.state(rls);
mw.loader.load("https://wiki.riteme.site/w/index.php?title=User:PerfektesChaos/js/"+this.supply+"/r.js&action=raw&bcache=1&maxage=604805&ctype=text/javascript","text/javascript");}
};
config.firing=function(){
mw.hook(config.supply+".ready").add(fire);
};
config.folder=function(assign){
var s,sign=LRF.type+".store",r="";
if(typeof assign==="string"){
r=$.trim(assign).replace(/\\/g,"/");
if(typeof window.localStorage==="object"){
if(r===""){
window.localStorage.removeItem(sign);
this.stored=false;
}else{
window.localStorage.setItem(sign,r);
this.stored=r;}}
}else{
if(typeof LRF.store==="string"){
r=LRF.store;}
if(typeof this.stored==="string"){
r=this.stored;}
r=r.replace(/\\/g,"/");
if(typeof window.localStorage==="object"){
s=window.localStorage.getItem(sign);
if(typeof s==="string"){
r=$.trim(s).replace(/\\/g,"/");}
window.localStorage.setItem(sign,r);}}
this.storage=r;
return r;
};
config.foreign=function(assign){
var r=config.set;
if(typeof assign==="string"){
config.set=$.trim(assign);}
return(r?r:false);
};
config.form=function(){
var dialog,sl,text=lang.texts;
lang.favorite();
sl=lang.slang;
this.fetch();
dialog={script:LRF.type,show:text["^show"][sl],support:this.favorite(),suffix:text["^suffix"][sl],filled:this.filled,opts:[{signature:"path",type:"text",show:text["^^path"][sl],suffix:text["^^path+"][sl],val:this.folder()},{signature:"charset",type:"text",show:text["^^charset"][sl],suffix:text["^^charset+"][sl],val:(this.set?this.set:"")},{signature:"portlet",type:"checkbox",show:text["^^portlet"][sl],suffix:text["^^portlet+"][sl],val:(gui.portlet?true:false)}
]};
prego.form(dialog);
};
gui.factory=function(){
var dom,$link,s,show,signal,scope="p-tb",shortcut=null,stick=null;
lang.favorite();
show=lang.texts.show[lang.slang];
s=gui.portlet.scope;
if(typeof s==="string"){
s=$.trim(s);
if(s.length){
scope=s;}}
s=gui.portlet.shortcut;
if(typeof s==="string"){
s=$.trim(s);
if(s.length){
shortcut=s;}}
s=gui.portlet.show;
if(typeof s==="string"){
s=$.trim(s);
if(s.length){
show=s;}}
s=gui.portlet.stick;
if(typeof s==="string"){
s=$.trim(s);
if(s.length){
stick=s;}}
s=config.foreign();
signal=show+"\n"+config.folder()+"\n"+(s?s+"\n":"")+LRF.type+" "+LRF.vsn;
dom=mw.util.addPortletLink(scope,"#",show,"t-"+LRF.type,signal,shortcut,stick);
$link=$(dom).find("a");
$link.click(LRF.find);
};
gui.file=function(access){
if(!this.$input){
this.$input=$("<input />",{type:"file",id:LRF.type,accept:".css,.js",multiple:true
});
this.$input.hide();}
$("#"+LRF.type).remove();
this.$file=this.$input.clone();
this.$file.change(this.found);
$("body").append(this.$file);
this.storage=access;
this.$file=this.$file[0];
this.$file.click();
};
gui.found=function(){
var collection,entry,s,bag=gui.$file.files;
if(bag){
collection=[];
for(s in bag){
entry=bag[s];
if(typeof entry.name==="string"){
collection.push(entry.name);}}
basics.files(collection,gui.storage,config.set);}
gui.$file.remove();
};
lang.favorite=function(){
var s;
if(!this.slang){
s=mw.config.get("wgUserLanguage").toLowerCase();
if(s.length>4){
if(s.charCodeAt(2)===45){
s=s.substr(0,2);}}
s=this.user[s];
this.slang=(s?s:"en");}
};
LRF.find=function(access){
var storage=config.filter(access);
if(storage){
gui.file(storage);
}else{
lang.favorite();
window.alert(lang.texts.sucks[lang.slang]);}
};
LRF.folder=function(access){
return config.folder(access);
};
LRF.loadFiles=function(apply,access,accept){
var set,storage=config.filter(access);
if(storage){
switch(typeof accept){
case "boolean":
case "string":
set=accept;
break;
default:
set=config.foreign();}
basics.files(apply,storage,set);
}else{
lang.favorite();
window.alert(lang.texts.sucks[lang.slang]);}
};
LRF.setCharset=function(accept){
config.foreign((accept?accept:""));
};
LRF.loaded=true;
config.fire();
mw.loader.using(["user","user.options","mediawiki.util"],config.firing);
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>loadResourceFile/r.js