User:Skizzerz/Scripts/AjaxPatrol.js

/** * AJAX patrol feature version 1.0 * by Ryan Schmidt < http://strategywiki.org/wiki/User:Ryan_Schmidt > */

/* * CONFIGURATION * You may set whether or not to automatically browse to the next diff * By placing the following BEFORE the importScript call: * var AjaxPatrolAutoNext = true; */

AjaxPatrol = new function { this.setup = function { var links = getElementsByClassName(document, 'span', 'patrollink'); for(var i=0; i<links.length; i++) { addClickHandler(links[i].getElementsByTagName('a')[0], function(e) { AjaxPatrol.patrol(e); }); }	};

this.patrol = function(e) { var a = e.target || e.srcElement; var next; var ajax = this.ajaxRequest; if(ajax) { this.message(' Patrolling edit, please wait... '); var origt = document.title; document.title = '(' + origt + ')'; ajax.onreadystatechange = function { if(ajax.readyState == 4) { if(AjaxPatrolAutoNext && (next = document.getElementById('differences-nextlink'))) { AjaxPatrol.message(' Done. Loading next diff... '); window.location = next.href; } else { AjaxPatrol.message(' Done. You may now browse away from the page. '); document.title = origt; }				}			};			ajax.open('GET', a.href, true); ajax.send(null); e.preventDefault; }	};

this.ajaxRequest = function { var ret = false; try { ret = new XMLHttpRequest; } catch(e) { try { ret = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { ret = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { return false; }			}		}		return ret; };

this.message = function(msg) { var div; if(!(div = document.getElementById('ajaxpatrol-box'))) { div = document.createElement('div'); div.className = 'header_box'; div.id = 'ajaxpatrol-box'; div.innerHTML = msg; this.firstHeading.parentNode.insertBefore(div, this.firstHeading); } else { div.innerHTML = msg; }	};

this.firstHeading = document.getElementsByTagName('h1')[0]; };

addOnloadHook(function {	if(typeof AjaxPatrolAutoNext == 'undefined') {		AjaxPatrolAutoNext = false;	}	AjaxPatrol.setup; });