User:NaomiAmethyst/autoroll.js

function urlencode(str) { str = escape(str); str = str.replace('+', '%2B'); str = str.replace('%20', '+'); str = str.replace('*', '%2A'); str = str.replace('/', '%2F'); str = str.replace('@', '%40'); return str; }

function revertandwarn (page,vandal,oldid) { document.getElementById('mw-diff-ntitle4').getElementsByTagName('strong')[0].nodeValue = "(Sending ...)"; var req = new XMLHttpRequest; req.open('GET', 'http://c.c/wprevertandwarn.php?title=' + urlencode(page) + '&vandal=' + urlencode(vandal) + '&id=' + urlencode(oldid), true); req.onreadystatechange = function (aEvt) { if (req.readyState == 4) { if(req.status == 200) document.getElementById('mw-diff-ntitle4').getElementsByTagName('strong')[0].nodeValue = "(Sent)"; else document.getElementById('mw-diff-ntitle4').getElementsByTagName('strong')[0].nodeValue = "(ERROR)"; } };  req.send(null); document.getElementById('mw-diff-ntitle4').getElementsByTagName('strong')[0].nodeValue = "(Waiting ...)"; }

//I stole borrowed a lot of this from User:AzaToth/twinklefluff.js function cobirawadd { var spanTag = function( color, content ) { var span = document.createElement( 'span' ); span.style.color = color; span.appendChild( document.createTextNode( content ) ); return span; }

var otitle = getElementsByClassName( document.getElementById('bodyContent'), 'td', 'diff-otitle' )[0]; var ntitle = getElementsByClassName( document.getElementById('bodyContent'), 'td', 'diff-ntitle' )[0]; if( !ntitle ) { // Nothing to see here, move along... return; }	if( !otitle.getElementsByTagName('a')[0] ) { // no previous revision available return; }	// Lets first add a [edit this revision] link var query = new QueryString( decodeURI( otitle.getElementsByTagName( 'a' )[0].getAttribute( 'href' ).split( '?', 2 )[1] ) ); if( ntitle.getElementsByTagName('a')[0].firstChild.nodeValue != 'Current revision' ) { // not latest revision curVersion = false; return; }

vandal = ntitle.getElementsByTagName('a')[3].firstChild.nodeValue.replace("'", "\\'"); var vandNode = document.createElement('strong'); var vandLink = document.createElement('a'); vandLink.href = "javascript:revertandwarn('" + query.get( 'title' ) + "', '" + vandal + "' , '" + query.get( 'oldid' ) + "')";

vandLink.appendChild( spanTag( 'Black', '(' ) );	vandLink.appendChild( spanTag( 'Blue', 'roll and warn' ) );	vandLink.appendChild( spanTag( 'Black', ')' ) );

vandNode.appendChild(vandLink);

document.getElementById('mw-diff-ntitle4').appendChild(vandNode); }

var isDiff = /[?&]diff=/.test(document.location.href); if (isDiff) { addOnloadHook(cobirawadd); }