User:Enterprisey/url-select-revdel.js

$( function () {

if( mw.config.get( "wgAction" ) === "history" ) {

mw.loader.using( [ "mediawiki.util" ], function () {

var param = mw.util.getParamValue( "revdel_select" );

if( param ) {

var pageHistory = document.getElementById( "pagehistory" );

var oldids = param.split( "|" ).filter( Boolean );

if( oldids.some( function ( oldid ) { return oldid.indexOf( ".." ) >= 0; } ) ) {

var allCheckboxes = Array.prototype.slice.call( pageHistory.querySelectorAll( "input[name^='ids[']" ) );

}

function expandRange ( 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 = [];

if( !startCheckbox ) throw( "No checkbox found for revision " + start );

if( !endCheckbox ) throw( "No checkbox found for revision " + end );

for( var idx = startIdx, inc = Math.sign( endIdx - startIdx );

idx != endIdx; idx += inc ) {

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] + "]']" );

}

}

if( singletonSelectors.length ) {

Array.prototype.slice.call( document.querySelectorAll(

singletonSelectors.join( "," ) ) ).forEach( makeChecked );

}

}

} );

}

} );