User:A930913/vada/plugin/av.js

var av={}; av.about={ name:"Anti Vandal Test", description:"Plugin to test vada and make an antivandal tool", namespace:"av", userscript:"User:A930913/vada/plugin/av.js", } if(typeof window=="undefined"){ //inside vada process vada.plugins.av.displayRecentChanges=function(evt){ var p=new vada.Page(evt.rc.title); if(p.namespace)return;//if not mainspace if(vada.dom._diff.rightRevision && vada.dom._diff.rightRevision.title==p.title)return vada.plugins.av.queueClicked({title:p.title});//load if current var r=p.getLatestRevision; var u=r.user; if(vada.dom.queue.indexOf(p)!=-1)vada.dom.queue.splice(vada.dom.queue.indexOf(p),1);//remove old revision if(vada.plugins.av.whitelist.indexOf(u.name)!=-1)return; var score=0; if(u.reported)score+=50000; if(u.inCache("warnlevel"))score+=(u.warnlevel||0)*10000; if(/\u2190<\/a>Replaced content/.exec(r.parsedcomment) || false) score+=1200; if(/\u2190<\/a>Blanked the page/.exec(r.parsedcomment) || false) score+=1500; score+=r.tags.length*300; if(u.reverted||false)score+=1100; if((/\*\/\s*(.*)/.exec(r.comment) || [0,r.comment])[1]=="")score+=1000; if(u.isAnonymous)score+=100; if(Math.abs(r.size-r.parent.size)>500)score+=50; score+=9-(p.title.match(/ /g)||[]).length; p.score=score; vada.dom.queue.push(p);//TODO insert according to score vada.dom.queue.sort(function(a,b){return a.score==b.score?(a.title>b.title?-1:1):b.score-a.score;}); if(vada.dom.queue.length>100)vada.dom.queue.pop; vada.dom.queue.redraw; }	vada.plugins.av.queueClicked=function(params){ var p=new vada.Page(params.title); var r=p.getLatestRevision; var l=r; while(l.user==r.user)l=l.parent; vada.dom.load(l,r); vada.dom.extraInfo(r.user.warns.join(" ")); vada.dom.queue.splice(vada.dom.queue.indexOf(new vada.Page(params.title)),1); vada.dom.queue.redraw; }	vada.plugins.av.previousClicked=function{ var r=vada.dom._diff.leftRevision.parent; vada.dom.load(r.revid?r:vada.dom._diff.leftRevision,vada.dom._diff.rightRevision); }	vada.plugins.av.nextClicked=function{ var r=vada.dom._diff.leftRevision.child; vada.dom.load(r.revid==vada.dom._diff.rightRevision.revid?vada.dom._diff.leftRevision:r,vada.dom._diff.rightRevision); }	vada.plugins.av.pageToDOM=function{ var item=vada.plugins.av.pageToDOMBackup.call(this); var classes=[]; var r=this.getLatestRevision; var u=r.user; if(u.isAnonymous) classes.push("anon"); if(/\u2190<\/a>Replaced content/.exec(r.parsedcomment) || false) classes.push("replaced"); if(/\u2190<\/a>Blanked the page/.exec(r.parsedcomment) || false) classes.push("blanked"); if(r.tags.length){ classes.push("tag"); item.data.af=r.tags.length; }		if(u.reverted||false) classes.push("reverted"); if(u.inCache("warns") && u.warnlevel>0) classes.push("warn"+u.warnlevel); if(u.reported) classes.push("reported"); if(u.reverted===true) classes.push("reverted"); if(u.inCache("blocked") && u.blocked) classes.push("blocked"); item.classes=[item.classes,classes.join(" ")].join(" "); return item; }	vada.plugins.av.fetchWhitelist=function{ vada.plugins.av.whitelist=[]; var xhr=new XMLHttpRequest; xhr.open("GET","//huggle.wmflabs.org/data/wl.php?wp=en.wikipedia&action=read",true); xhr.onreadystatechange=vada.plugins.av.parseWhitelist; xhr.send }	vada.plugins.av.parseWhitelist=function(text){ if (this.readyState==4 && this.status==200)vada.plugins.av.whitelist=this.responseText.split("|"); }	vada.plugins.av.start=function{ vada.events.trigger("plugins.stop",{}); vada.events.addListener("plugins.stop",vada.plugins.av.stop); vada.plugins.av.running=true; vada.dom.menu.new([vada.dom.menu.buttons.nextq,vada.dom.menu.buttons.revertwarn,vada.dom.menu.buttons.revert,vada.dom.menu.buttons.template,vada.dom.menu.buttons.warn,vada.dom.menu.buttons.thank,vada.dom.menu.buttons.previous,vada.dom.menu.buttons.next]); vada.events.addListener("rc.newedit",vada.plugins.av.displayRecentChanges); vada.events.addListener("queue.page.selected",vada.plugins.av.queueClicked); vada.events.addListener("previous.click",vada.plugins.av.previousClicked); vada.events.addListener("next.click",vada.plugins.av.nextClicked); vada.plugins.av.fetchWhitelist; vada.plugins.av.pageToDOMBackup=vada.Page.prototype.toDOM; vada.Page.prototype.toDOM=vada.plugins.av.pageToDOM; }	vada.plugins.av.stop=function{ vada.plugins.av.running=false; vada.Page.prototype.toDOM=vada.plugins.av.pageToDOMBackup; vada.events.removeListener("plugins.stop",vada.plugins.av.stop); vada.events.removeListener("rc.newedit",vada.plugins.av.displayRecentChanges); vada.events.removeListener("queue.page.selected",vada.plugins.av.queueClicked); vada.events.removeListener("previous.click",vada.plugins.av.previousClicked); vada.events.removeListener("next.click",vada.plugins.av.nextClicked); }	vada.plugins.av.running=false; vada.plugins.av.button=new vada.dom.menu.Button("av_start"); vada.plugins.av.button.text="Anti Vandal"; vada.plugins.av.button.click=vada.plugins.av.start; vada.dom.menu.buttons.vada.children.push(vada.plugins.av.button); vada.dom.menu.redraw; } else { //inside vada DOM window.vada.loadPlugin(av); }