User:Makecat/Scripts/UndoRange.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.
//Copy of [[:zh:User:Liangent/Scripts/UndoRange.js]]

( function( $, mw ) { mw.loader.using( [
    'mediawiki.util'
], function() { $( function() {
    if ( mw.config.get( 'wgAction' ) == 'history' ) {
        $( '#mw-history-compare .mw-history-compareselectedversions-button' ).after(
            $( '<input type="submit" />' )
                .val( 'UndoRange' )
                .click( function( e ) {
                    $( '#mw-history-compare input[name=diff]' ).attr( 'name', 'undo' );
                    $( '#mw-history-compare input[name=oldid]' ).attr( 'name', 'undoafter' );
                    $( '#mw-history-compare input[name=action]' ).val( 'edit' );
                    $( '<input type="hidden" name="summary" />' ).val(
                        '[[WP:UNDO|Undid]] edits between revision ' + $( '#mw-history-compare input:checked[name=undoafter]' ).val()
                            + ' and ' + $( '#mw-history-compare input:checked[name=undo]' ).val() + '.'
                    ).insertAfter( this );
                } )
        );
    }
} ); } ); } )( jQuery, mediaWiki );