User:PerfektesChaos/js/autoBackup/r.js

/// User:PerfektesChaos/js/autoBackup/r.js

/// 2019-07-01 PerfektesChaos@de.wikipedia

/// Fingerprint:#0#2860E0F5#

/// @license:CC-by-sa/4.0

///

(function(mw,$){

"use strict";

var VERSION=2.3,BAK="autoBackup";

if(typeof mw.libs[BAK]!=="object"||!mw.libs[BAK]){

mw.libs[BAK]={};}

mw.libs[BAK].type=BAK;

BAK=mw.libs[BAK];

BAK.doc="w:en:User:PerfektesChaos/js/"+BAK+"";

BAK.vsn=VERSION;

BAK.cnf={maxAge:72,maxHist:5,maxPages:10,maxRev:3,mid:5,msec:300000};

BAK.disk={self:"AutoBackupPerfectChaos",stick:"newest|subject"};

BAK.gui={};

BAK.util={};

if(!typeof BAK.opt||typeof BAK.opt!=="object"){

BAK.opt={};}

BAK.cnf.text={

"BAKself":{"en":"AutoBackup",

"de":"AutoBackup"},

"IntJSONparse":{"en":"Internal ERROR -- JSON.parse",

"de":"Interner FEHLER -- JSON.parse"},

"NoLSavail":{"en":"No localStorage available",

"de":"Kein localStorage zugreifbar"},

"otherPages":{"en":"Other Pages",

"de":"Andere Seiten"},

"pending":{"en":"Recover from pending abort?",

"de":"Wiederherstellung nach Abbruch?"},

"setItemExcept":{"en":"ERROR setting localStorage",

"de":"FEHLER beim Setzen im localStorage"},

"thisPage":{"en":"this page",

"de":"diese Seite"},

"VanishedLS":{"en":"ERROR: localStorage vanished",

"de":"FEHLER: localStorage verschwunden"},

"WriteCrash":{"en":"Crash on localStorage write attempt",

"de":"Schreibversuch auf localStorage versagt"}

};

BAK.cnf.translang={

"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"

};

BAK.cnf.favorite=function(){

var s;

if(!this.slang){

s=mw.config.get("wgUserLanguage").toLowerCase();

s=this.translang[s];

if(s){

this.slang=s;

}else{

this.slang="en";}}

};

BAK.cnf.feature=function(apply){

var e,r;

if(!this.slang){

this.favorite();}

e=this.text[apply];

if(e){

r=e[this.slang];

if(!r){

r=e.en;

if(!r){

r="???"+apply+"???";}}

}else{

r="***"+apply+"***";}

return r;

};

BAK.cnf.fetch=function(){

if(!this.load){

if(typeof BAK.opt==="object"){

if(typeof BAK.opt.maxAge==="number"){

if(BAK.opt.maxAge>=0){

this.maxAge=Math.floor(BAK.opt.maxAge);}}

if(typeof BAK.opt.maxHist==="number"){

if(BAK.opt.maxHist>=1){

this.maxHist=Math.ceil(BAK.opt.maxHist);}}

if(typeof BAK.opt.maxPages==="number"){

if(BAK.opt.maxPages>=1){

this.maxPages=Math.ceil(BAK.opt.maxPages);}}

if(typeof BAK.opt.maxRev==="number"){

if(BAK.opt.maxRev>=1){

this.maxRev=Math.ceil(BAK.opt.maxRev);}}

if(BAK.learn){

if(typeof BAK.opt.mid==="number"){

if(BAK.opt.mid>0){

this.mid=BAK.opt.mid;

}else{

this.mid=false;}}

if(this.mid){

this.msec=this.mid*60000;

}else{

this.msec=false;}

if(BAK.opt.portlet){

BAK.gui.facility();}}}

this.load=true;}

};

BAK.disk.fetch=function(){

var s;

BAK.pages=false;

if(typeof window.localStorage==="object"){

BAK.family();

s=window.localStorage.getItem(this.storage);

if(s){

try{

BAK.pages=JSON.parse(s);

}catch(e){

BAK.gui.flag("IntJSONparse",false);

window.localStorage.setItem(this.storage,"");}}

}else{

BAK.gui.flag("NoLSavail",false);

this.lock=true;}

};

BAK.disk.flush=function(){

var store=false,s;

if(typeof BAK.pages==="object"){

for(s in BAK.pages){

store=true;

break;}}

if(!store){

this.pages=false;}

if(typeof window.localStorage==="object"){

if(BAK.pages){

store=JSON.stringify(BAK.pages);

if(store==="{}"){

store="";}

}else{

store="";}

try{

window.localStorage.setItem(this.storage,store);

s=window.localStorage.getItem(this.storage);

if(s!==store){

BAK.gui.flag("WriteCrash",false);}

}catch(e){

BAK.gui.flag("setItemExcept",false);}

window.localStorage.setItem(this.storage,store);

}else{

BAK.gui.flag("VanishedLS",false);}

};

BAK.gui.face=function(apply){

var s;

if(!this.$div){

mw.util.addCSS(".cn-fundraiser-banner,#mw-js-message,#siteNotice,#fundraising\n{display: none ! important;}");

this.$div=$("

");

if(!this.$top){

this.$top=$("#mw-content-text");

if(this.$top.length){

this.$top.prepend(this.$div);

}else{

this.$top=$("#bodyContent");

if(!this.$top.length){

this.$top=$("#article");

if(!this.$top.length){

this.$top=$("#content");

if(!this.$top.length){

this.$top=BAK.$page;}}}

this.$top.before(this.$div);}}}

if(apply){

if(this.$msg){

this.$msg.empty();

}else{

this.$msg=$("

");

this.$div.prepend(this.$msg);}

if(this.$msg){

s="display: block;font-size: 120%;";

this.$msg.attr("style",s);

this.$msg.append(apply);}

}else{

if(this.$msg){

this.$msg.attr("style","display: none;");}}

};

BAK.gui.facility=function(){

var portlet,$portlet;

if(!BAK.cnf.self){

BAK.cnf.self=BAK.cnf.feature("BAKself");}

portlet=mw.util.addPortletLink("p-cactions","#",BAK.cnf.self,"ca-"+BAK.type);

$portlet=$(portlet);

$portlet.click(BAK.fresh);

$portlet.attr({title:BAK.type+" "+BAK.vsn});

};

BAK.gui.feed=function(){

var r=false,$form,$ta;

if(this.leading){

this.leading=false;

this.$editform=false;

this.$textarea=false;

$form=BAK.$page.find("#editform");

if($form){

$ta=BAK.$page.find("#wpTextbox2");

if($ta.length){

r=$ta.val();}

$ta=$form.find("#wpTextbox1");

if($ta.length){

if(!$ta.attr("readonly")){

this.$editform=$form;

this.$textarea=$ta;}}}}

if(this.$textarea&&!r){

if(window.wikEd&&typeof window.wikEd==="object"&&!window.wikEd.disabled&&window.wikEd.turnedOn&&window.wikEd.useWikEd&&window.wikEd.UpdateTextarea){

window.wikEd.UpdateTextarea();}

r=this.$textarea.val();}

return r;

};

BAK.gui.fence=function(apply){

this.$div.attr("style",(apply?"border: solid 1px #606060; border-bottom: solid 5px #606060; padding: 0.5em; margin-bottom: 2em;":null));

};

BAK.gui.fiat=function(action,add){

var r;

switch(action){

case "ALL":

case "SHOW":

r="*";

break;

case "DELETE":

r="X";

break;

default:

r="";}

if(r){

r="\n   \n";}

return r;

};

BAK.gui.fill=function(){

var page=BAK.pages[BAK.pageID],revs=false,i,n,s;

BAK.gui.$msg.find("#autoBackupALL").remove();

if(BAK.gui.$box){

BAK.gui.$box.remove();}

if(page){

BAK.gui.$box=$("

");

BAK.gui.$msg.after(BAK.gui.$box);

if(!BAK.revID){

BAK.revID=mw.config.get("wgCurRevisionId");}

for(i in page){

if(BAK.disk.stick.indexOf(i)<0){

s=page[i].newest+" "+i;

if(revs){

revs.push(s);

}else{

revs=[s];}}}

n=revs.length;

revs.sort();

for(i=revs.length-1;i>=0;i--){

BAK.gui.folder(revs[i],page);}

BAK.gui.fence(true);

}else{

BAK.gui.face(false);}

};

BAK.gui.finish=function(access){

var $btn=this.$editform.find("#"+access);

if($btn.length){

$btn.click(BAK.fresh);}

};

BAK.gui.flag=function(apply,action){

var s;

if(!BAK.cnf.self){

BAK.cnf.self=BAK.cnf.feature("BAKself");}

s=BAK.cnf.feature(apply);

s="

\n"+""+BAK.cnf.self+"  \n"+(action?"":"")+s+(action?"\n":"\n")+this.fiat(action)+"
\n";

this.face(s);

if(action){

this.form(action,"");}

};

BAK.gui.folder=function(access,album){

var e=access.split(" "),k=e[1],s="autoBackupR"+k,i,w,$div,$textarea;

this.$box.append("

");

$div=this.$box.find("#"+s);

if(parseInt(k,10)===BAK.revID){

s=k+" ("+BAK.cnf.feature("thisPage")+")";

}else{

s=mw.config.get("wgArticlePath");

s=""+k+"";}

s="

oldid="+s+"

";

s=s+this.fiat("DELETE",k);

$div.append(s);

this.form("DELETE",k);

e=album[k].history;

for(i=0;i

k=e[i];

w=k[1];

s="

"+BAK.util.focus(k[0])+"

"+w.length+" bytes

";

$div.append(s);

$textarea=$("