Jump to content

User:Bellezzasolo/Scripts/ajaxrollsum.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.
/**
 * Ajax Undo links
 *
 * Adds an Ajax undo link next to the normal undo link on page histories
 * and on diff pages
 * Based on [[User:Abelmoschus Esculentus/AjaxRollback.js]]
 */
 //<nowiki>
//Modified from [[User:BenjaminWillJS/AjaxRollback.js]]
jQuery(document).ready(function ($) {
	function CreateUndoLink(parentObj) {
		var rollbackLink = $( '<a />' ).text( 'Rollback Summary' ).attr( 'href', '#' ).click(function(e) {
			e.preventDefault();
			var $rblink = $(parentObj);
			var href = parentObj.href;
			console.log(href);
			var summary = prompt("Enter optional summary", "");
			if (summary === null)
			{
				return;
			}
			var summarystr = "";
			if (summary !== "")
			{
				summarystr = "&summary=" + summary;
			}
			this.innerHTML = '<img src="https://images2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif" style="vertical-align: baseline;" height="15" width="15" border="0" alt="Rollingback..." />';
			$.ajax({
				url: href + summarystr,
				success: function() {
					$rblink.text(function (i, val) {return val + '[reverted]';});
				},
				error: function() {
					$rblink.text(function (i, val) {return val + '[rollback failed]';});
				}
			});
		});
		return rollbackLink;
	}
	function SetAjaxRollback() {
		$( '.mw-rollback-link > a' ).each( function () {
			$ajaxUndoLink = CreateUndoLink( this );
			$( this ).parent().after( ' | ', $ajaxUndoLink );
		} );
	}
	mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Title', 'mediawiki.RegExp'], function() {
		SetAjaxRollback();
	});
});
//</nowiki>