User:A930913/vada/plugin/cbngav.js

if(typeof window=="undefined"){ //inside vada process vada.plugins.cbngav.displayRecentChanges=function(evt){ var xhr=new XMLHttpRequest; xhr.open("GET","//tools.wmflabs.org/cluestuff/cgi-bin/vada/cbngget.py",false); xhr.send; var pages=JSON.parse(xhr.responseText); while(vada.dom.queue.pop){} for(var i in pages){ if(vada.dom.diff.leftRevision instanceof vada.Revision && pages[i]["title"]==vada.dom.diff.leftRevision.title)continue; if(vada.plugins.cbngav.inSkip(pages[i]))continue; var p=new vada.Page(pages[i]["title"]); p.score=(pages[i]["score"]=="N/A"?1:pages[i]["score"]); vada.dom.queue.push(p); }		vada.dom.queue.redraw; }	vada.plugins.cbngav.inSkip=function(o){ for(var i in vada.plugins.cbngav.skips){ if(o.title==vada.plugins.cbngav.skips[i].title && (o.score=="N/A"?1:o.score)==vada.plugins.cbngav.skips[i].score)return true; }		return false; }	vada.plugins.cbngav.queueClicked=function(params){ var p=new vada.Page(params.title); var r=p.getLatestRevision; var l=r; try{while(l.user==r.user)l=l.parent}catch(e){l=r.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.cbngav.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.cbngav.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.cbngav.innocentClicked=function{ var t=vada.dom.diff.leftRevision.title; vada.dom.queue.next; var xhr=new XMLHttpRequest; xhr.open("POST","//tools.wmflabs.org/cluestuff/cgi-bin/vada/cbngrm.py",false); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xhr.send(vada.api._kwarg_to_poststring({title:t})); if(JSON.parse(xhr.responseText).status!=200){ if(typeof console!="undefined")console.log("ClueBot AV: Error sending '"+t+"' as innocent"); }	}	vada.plugins.cbngav.skips=[]; vada.plugins.cbngav.skipClicked=function{ var p=new vada.Page(vada.dom.diff.leftRevision.title); vada.plugins.cbngav.skips.push({score:p.score,title:p.title}); vada.dom.queue.next; }	vada.plugins.cbngav.pageToDOM=function{ var item=vada.plugins.cbngav.pageToDOMBackup.call(this); item.style+="background-color:rgb("+parseInt(Math.min(255,this.score*340))+","+parseInt((this.score>0.75)?127-((this.score-0.75)*510):(255-this.score*169))+",0);"; return item; }	vada.plugins.cbngav.start=function{ vada.events.trigger("plugins.stop",{}); vada.events.addListener("plugins.stop",vada.plugins.cbngav.stop); vada.plugins.cbngav.running=true; vada.dom.menu.new([vada.dom.menu.buttons.nextq,vada.dom.menu.buttons.innocent,vada.plugins.cbngav.skip,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.plugins.cbngav.timer=setInterval(vada.plugins.cbngav.displayRecentChanges,5000); vada.events.addListener("queue.page.selected",vada.plugins.cbngav.queueClicked); vada.events.addListener("previous.click",vada.plugins.cbngav.previousClicked); vada.events.addListener("next.click",vada.plugins.cbngav.nextClicked); vada.events.addListener("innocent.click",vada.plugins.cbngav.innocentClicked); vada.plugins.cbngav.pageToDOMBackup=vada.Page.prototype.toDOM; vada.Page.prototype.toDOM=vada.plugins.cbngav.pageToDOM; vada.plugins.cbngav.displayRecentChanges; }	vada.plugins.cbngav.stop=function{ vada.plugins.cbngav.running=false; vada.Page.prototype.toDOM=vada.plugins.cbngav.pageToDOMBackup; vada.events.removeListener("plugins.stop",vada.plugins.cbngav.stop); clearInterval(vada.plugins.cbngav.timer); vada.events.removeListener("queue.page.selected",vada.plugins.cbngav.queueClicked); vada.events.removeListener("previous.click",vada.plugins.cbngav.previousClicked); vada.events.removeListener("next.click",vada.plugins.cbngav.nextClicked); vada.events.removeListener("innocent.click",vada.plugins.cbngav.innocentClicked); }	vada.plugins.cbngav.running=false; vada.plugins.cbngav.button=new vada.dom.menu.Button("cbngav_start"); vada.plugins.cbngav.button.text="ClueBot Anti Vandal"; vada.plugins.cbngav.button.click=vada.plugins.cbngav.start; vada.plugins.cbngav.skip=new vada.dom.menu.Button("cbngav_skip"); vada.plugins.cbngav.skip.image="//upload.wikimedia.org/wikipedia/commons/c/c4/Ambox_blue_question.svg"; vada.plugins.cbngav.skip.text="Not Sure - Skip"; vada.plugins.cbngav.skip.click=vada.plugins.cbngav.skipClicked; vada.dom.menu.buttons.vada.children.push(vada.plugins.cbngav.button); vada.dom.menu.redraw; } else { //inside vada DOM (function{		var cbngav={};		cbngav.about={			name:"ClueBot Anti Vandal",			description:"Anti vandal tool that uses ClueBot NG to find the vandalism",			namespace:"cbngav",			userscript:"User:A930913/vada/plugin/cbngav.js",		}		window.vada.loadPlugin(cbngav);	}); }