User:Seizefire/etils.js

// Etils 0.0.2 // This was originally a tampermonkey script I made

var waitForElementQS = function(element,time,callback,freq=250,elemindex=0){ var t = 0; var tm = time/freq; var interval = setInterval(function{		if(document.querySelectorAll(element)[elemindex]){			clearInterval(interval);			callback(document.querySelectorAll(element)[elemindex]);		}else if(t == tm){			clearInterval(interval);		}else{			t++;		}	},freq); }; var lget = function{return JSON.parse(localStorage.getItem("etils____dataxd")||"{}")}; var lstore = function(obj){localStorage.setItem("etils____dataxd",JSON.stringify(obj))};

waitForElementQS("textarea#wpTextbox1",30000,function(tb){	var a = lget,c = false,d = false;	if(!a.ec) a.ec = {};	if(!a.ase) a.ase = ],[;	lstore(a);	var b = location.search; b = b.substring(b.indexOf("title=")+6);b=b.substring(0,b.indexOf("&")>-1?b.indexOf("&"):b.length);	if(document.querySelector("h1#firstHeading").innerText.trim.startsWith("Creating")){d = true;}	if(a.ec[b]){tb.value = a.ec[b];c = true;	}else if(a.ase[1].indexOf(b)>-1){c = true;	}else if(a.ase[0].indexOf(b)>-1){	}else if(document.querySelector("h1#firstHeading").innerText.trim.startsWith("Creating")){c = true;}	var e = new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({name:'autosaveEnabled',selected:c}),{label:'Enable Auto-Save',align:'inline'});	e.$field[0].querySelector("input").addEventListener("change",function{ a = lget; c = e.$field[0].querySelector("input").checked; if(c){ if(d){a.ase[0].splice(a.ase[0].indexOf(b),1);}else{a.ase[1].push(b);} if(tb.value.trim.length>0) a.ec[b] = tb.value; lstore(a); }else{ if(d){a.ase[0].push(b);}else{a.ase[1].splice(a.ase[1].indexOf(b),1);} delete a.ec[b]; lstore(a); }	});	var f = document.createElement("div");	f.setAttribute("class","oo-ui-layout oo-ui-labelElement oo-ui-fieldLayout oo-ui-fieldLayout-align-inline");	f.appendChild(e.$body[0]);	document.querySelector("div#mw-editpage-watch").parentNode.appendChild(f);	var g = true;	document.querySelector("form#editform.mw-editform").addEventListener("submit",function{ a = lget; g = false; delete a.ec[b]; if(a.ase[0].indexOf(b) > -1) a.ase[0].splice(a.ase[0].indexOf(b),1); if(a.ase[1].indexOf(b) > -1) a.ase[1].splice(a.ase[1].indexOf(b),1); lstore(a); });	window.addEventListener("beforeunload",function{ if(g){ a = lget; if(c && tb.value.trim.length>0) a.ec[b] = tb.value; lstore(a); }	}); });