User:Skizzerz/Scripts/AjaxPatrol.js

/** * AJAX patrol feature version 1.1 * 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.interval = [null, 0];

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); }); }		AjaxPatrol.firstHeading = document.getElementsByTagName('h1')[0]; };

this.patrol = function(e) { var a = e.target || e.srcElement; var next; var ajax = this.ajaxRequest; if(ajax) { this.dotmessage('Patrolling edit, please wait'); var origt = document.title; document.title = '(' + origt + ')'; ajax.onreadystatechange = function { if(ajax.readyState == 4) { clearInterval(AjaxPatrol.interval[0]); if(AjaxPatrolAutoNext && (next = document.getElementById('differences-nextlink'))) { AjaxPatrol.dotmessage('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.dotmessage = function(msg) { this.interval[1]++; if(this.interval[1] > 3) this.interval[1] = 0; var extra = ''; for(var i=0; i<this.interval[1]; i++) { extra += '.'; }		this.interval[0] = setInterval('AjaxPatrol.dotmessage("'+msg+'")', 500); this.message(msg + extra); }

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 + ' '; }	}; };

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