User:JJMC89/ajaxRollback.js

/** * Makes rollback links for edits execute without an additional page load. Adds a link to allow the user change the edit summary. * @author JJMC89 * @documantation https://ddowiki.com/page/User:JJMC89/ajaxRollback * @source https://ddowiki.com/page/User:JJMC89/ajaxRollback.js */ function ajaxRollback { var	$rollbackLinks = $('.mw-rollback-link a'), prevUser, rollbackSummaryDefault; function useAJAX(e) { e.preventDefault; var $this = $(this); var href = $this.attr( 'href' ) + '&bot=1'; $this.text('Rolling back...'); $rollbackLinks = $this.parent; $.get(			href,			null,			function( data, status, request ) {				if ( status == 'success' ) {					$this.html(' Rolled back ');				} else {					$this.html(' Rollback failed ');				}			}		); }	if ( $rollbackLinks.length > 0 ) { rollbackSummaryDefault = 'Reverted edits by $2 (talk) to last version by $1'; $rollbackLinks.each(function{			var $this = $(this);			$this.after( $this.clone .text('rollback: edit summary') .attr( 'class', '') .click(function confirmRollback( e ) {					var summary = prompt( "Enter an edit summary to use for the rollback:\n(Leave as provided to use the wiki default.)", "Reverted edits by $2 (talk) to last version by $1" );					if (summary == null || summary == "") return false;					else if (summary == "Reverted edits by $2 (talk) to last version by $1") return true;					this.href = this.href.replace("?", "?summary=" + encodeURIComponent(summary) + "&");					useAJAX.call(this, e);				} ) ).after( ' | ' )			.click( useAJAX );		}); } } $(ajaxRollback);