From StrategyWiki, the video game walkthrough and strategy guide wiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// 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();
});