Jump to content

User:Enterprisey/url-select-revdel.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Enterprisey (talk | contribs) at 07:28, 22 December 2018 (it's okay if some ranges are ""). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
$( function () {
    if( mw.config.get( "wgAction" ) === "history" ) {
        mw.loader.using( [ "mediawiki.util" ], function () {
            var param = mw.util.getParamValue( "revdel_select" );
            if( param ) {console.log(5)
                var pageHistory = document.getElementById( "pagehistory" );
                var oldids = param.split( "|" ).filter( Boolean );
                var expandRange = function ( _, __ ) { return []; };
                if( oldids.some( function ( oldid ) { return oldid.indexOf( ".." ) >= 0; } ) ) {
                    var allCheckboxes = [].slice.call( pageHistory.querySelectorAll( "input[name^='ids[']" ) );
                    expandRange = function ( range ) {
                        var start = range[0],
                            end = range[1],
                            startCheckbox = pageHistory.querySelector( "input[name='ids[" + start + "]']" ),
                            endCheckbox = pageHistory.querySelector( "input[name='ids[" + end + "]']" ),
                            startIdx = allCheckboxes.indexOf( startCheckbox ),
                            endIdx = allCheckboxes.indexOf( endCheckbox ),
                            checkboxes = [ startCheckbox ];
                        for( var idx = startIdx; idx < endIdx; idx++ ) {
                            checkboxes.push( allCheckboxes[ idx ] );
                        }
                        checkboxes.push( endCheckbox );
                        return checkboxes;
                    }
                }
                var singletonSelectors = [];
                function makeChecked( box ) { box.checked = true; }
                for( var i = 0, n = oldids.length; i < n; i++ ) {
                    if( oldids[i].indexOf( ".." ) >= 0 ) {
                        expandRange( oldids[i].split( ".." ) ).forEach( makeChecked );
                    } else {
                        singletonSelectors.push( "input[name='ids[" + oldids[i] + "]']" );
                    }
                }
                [].slice.call( document.querySelectorAll( singletonSelectors.join( "," ) ) )
                        .forEach( makeChecked );
            }
        } );
    }
} );