User:Najzere/ajaxpatrol.js

// Author: User:Ryan Schmidt // License: Unstated (CC-BY-SA) // Source: http://strategywiki.org/wiki/User:Ryan_Schmidt/Scripts/AjaxPatrol.js // Description: Moves to next diff when patrolling edits, or removes link if there isn't another diff. // Config: add "var AjaxPatrolAutoNext = true;" before importing script to turn on

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) { ajax.onreadystatechange = function { if(ajax.readyState == 4) { if(AjaxPatrolAutoNext && (next = document.getElementById('differences-nextlink'))) { window.location = next.href; } else { document.getElementById('mw-diff-ntitle4').style.display="none"; }				}			};			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; }; };

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