User:DannyS712/AjaxRollback.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
//Modified from [[User:BenjaminWillJS/AjaxRollback.js]]
//Copied from [[User:Abelmoschus Esculentus/AjaxRollback.js]
$(document).ready( function () {
	$('span.mw-rollback-link').click(function(e) {
		e.preventDefault();
		var $rblink = $(this);
		var href = this.getElementsByTagName('a')[0].href;
		this.innerHTML = '<img src="https://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif" style="vertical-align: baseline;" height="15" width="15" border="0" alt="Rollingback..." />';
		$.ajax({
			url: href,
			success: function() {
				$rblink.text(function (i, val) {return val + '[reverted]';});
			},
			error: function() {
				$rblink.text(function (i, val) {return val + '[rollback failed]';});
			}
		});
	});
});
//</nowiki>