User:A930913/vada/plugin/cleaner.js

if(typeof window!="undefined"){ //inside Vada DOM (function{		var a930913_cleaner={			about:{				name:"A930913's Cleaner",				description:"Cleans up articles. It's an amalgamation of various scripts.",				namespace:"a930913_cleaner",				userscript:"User:A930913/vada/plugin/cleaner.js",			}		}		window.vada.loadPlugin(a930913_cleaner);	}); } else { //inside Vada process vada.plugins.a930913_cleaner={}; vada.plugins.a930913_cleaner.page=function(params){ var p=new vada.Page(params.page); vada.dom.extraInfo("Spell Checking..."); var suggest=vada.plugins.a930913_cleaner.suggest(p.text); vada.dom.extraInfo("Cleaning with autoEd..."); wgPageName=p.title;//Leak global for autoEd var text=autoEdLinks(autoEdExtraBreaks(autoEdTablestoWikitext(autoEdTemplates(autoEdUnicodeControlChars(autoEdHeadlines(autoEdHTMLtoWikitext(autoEdWikilinks(autoEdUnicodeHex(autoEdWhitespace(autoEdISBN(autoEdUnicodify(suggest.text)))))))))))); text=vada.plugins.a930913_cleaner.reflinks(text); text=vada.plugins.a930913_cleaner.relativelinks(text); vada.dom.summarybox.setText((suggest.changes===""?"C":"Typo fixing, ("+suggest.changes+") and other c")+"leanup with A930913's Cleaner app"); vada.dom.minorbox.uncheck; vada.dom.load(p,text); }	vada.plugins.a930913_cleaner.queueclick=function(params){ vada.plugins.a930913_cleaner.page({page:params.title}); vada.dom.queue.splice(vada.dom.queue.indexOf(new vada.Page(params.title)),1); vada.dom.queue.redraw; }	vada.plugins.a930913_cleaner.suggest=function(text){ var changes=""; var typos=vada.plugins.a930913_cleaner.typos; for(var t in typos){ if(typos[t][0].test(text)){ var m=text.match(typos[t][0]); changes+=m[0]+'→'+m[0].replace(typos[t][0],typos[t][1])+((m.length>1)?" x"+m.length:"")+', '; text=text.replace(typos[t][0],typos[t][1]); }		}		if(changes)changes=changes.substr(0,changes.length-2); return {text:text,changes:changes}; }	vada.plugins.a930913_cleaner.relativelinks=function(text){ vada.dom.extraInfo(" Checking relative links... "); var linkre=/(\[|url=)(http.+?)[^\w\d\._~!\*'\(\);:@&=\+$,\/\?%#-]/gi; var link=null; while(link=linkre.exec(text)){ vada.dom.extraInfo(" Checking relative links... "+link[2]+"  "); var xhr=new XMLHttpRequest; xhr.open("get","//tools.wmflabs.org/cluestuff/cgi-bin/clean/relativelink.py?link="+encodeURIComponent(link[2]),false); xhr.send; data=JSON.parse(xhr.responseText); text=text.replace(link[1]+link[2],link[1]+data.link); }		vada.dom.extraInfo(""); return text; }	vada.plugins.a930913_cleaner.reflinks=function(text){ vada.dom.extraInfo(" Checking reflinks... "); var linkre=/ \s*\[?(https?:\/\/[^\] <]+)]?<\/ref>/gi; var link=null; while(link=linkre.exec(text)){ vada.dom.extraInfo(" Checking reflinks... "+link[1]+"  "); var xhr=new XMLHttpRequest; xhr.open("get","//tools.wmflabs.org/cluestuff/cgi-bin/vada/reflinks.py?url="+encodeURIComponent(link[1]),false); xhr.send; data=JSON.parse(xhr.responseText); text=text.replace(link[0],data.ref); }		vada.dom.extraInfo(""); return text; }	vada.plugins.a930913_cleaner.getTypos=function{ var t=new vada.Page("Wikipedia:AutoWikiBrowser/Typos").text; var r=//g; var typos={}; while(m=r.exec(t)){try{typos[m[1]]=[new RegExp(m[2],"g"),m[3]];}catch(e){if(typeof console!="undefined")console.log("A930913's Cleaner: Spellcheck: Invalid regex - "+m[1])}} return typos; }	vada.plugins.a930913_cleaner.start=function{ vada.events.trigger("plugins.stop",{}); vada.events.addListener("plugins.stop",vada.plugins.a930913_cleaner.stop); vada.dom.menu.new([vada.dom.menu.buttons.nextq,vada.dom.menu.buttons.save]); vada.dom.queue.builders.show; vada.events.addListener("pagename",vada.plugins.a930913_cleaner.page); vada.events.addListener("queue.page.selected",vada.plugins.a930913_cleaner.queueclick); vada.plugins.a930913_cleaner.running=true; if(vada.plugins.a930913_cleaner.first){ vada.plugins.a930913_cleaner.tfirst=false; var AutoEd_baseurl = '//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=Wikipedia:AutoEd/'; importScripts(AutoEd_baseurl + 'unicodify.js',				AutoEd_baseurl + 'isbn.js',				AutoEd_baseurl + 'whitespace.js',				AutoEd_baseurl + 'wikilinks.js',				AutoEd_baseurl + 'htmltowikitext.js',				AutoEd_baseurl + 'headlines.js',				AutoEd_baseurl + 'unicodecontrolchars.js',				AutoEd_baseurl + 'unicodehex.js',				AutoEd_baseurl + 'templates.js',				AutoEd_baseurl + 'tablestowikitext.js',				AutoEd_baseurl + 'extrabreaks.js',				AutoEd_baseurl + 'links.js'			); }		vada.plugins.a930913_cleaner.typos=vada.plugins.a930913_cleaner.getTypos; }	vada.plugins.a930913_cleaner.stop=function{ vada.plugins.a930913_cleaner.running=false; vada.dom.queue.builders.hide; vada.events.removeListener("pagename",vada.plugins.a930913_cleaner.page); vada.events.removeListener("queue.page.selected",vada.plugins.a930913_cleaner.queueclick); },	vada.plugins.a930913_cleaner.running=false, vada.plugins.a930913_cleaner.first=true, vada.plugins.a930913_cleaner.button=(function(pl){		var button=new vada.dom.menu.Button("a930913_cleaner_start");		button.text="A930913's Cleaner";		button.click=pl.start;		vada.dom.menu.buttons.vada.children.push(button);		vada.dom.menu.redraw;		return button;	})(vada.plugins.a930913_cleaner); }