User:Laser Dragon/revDelMultiple.js

// ================================================================== // RevisionDelete Multiple Entries // // Functions: //  * Adds the ability to select multiple entries at a time. //  * Replaces the "show/hide" links on history and log pages. //  * Selects all revisions between "compare diff" radio buttons. // ==================================================================

var rdmSelectCt,rdmLinkA,rdmLinkD,rdmLinkS; function revDelMultiple { var revDelLinks = getElementsByClassName(document, "span", "mw-revdelundel-link"); var notCombinedLog = document.documentElement.innerHTML.indexOf('Combined display') == -1; if (revDelLinks.length > 0 && (wgAction == "history" || wgPageName == "Special:Log") && notCombinedLog){ for (var i in revDelLinks){ var newCheck = document.createElement('input'); newCheck.setAttribute( 'type', 'checkbox' ); newCheck.setAttribute( 'name', 'rdmCheck' ); if (revDelLinks[i].innerHTML != "(show/hide)"){ var rdmHref = revDelLinks[i].firstChild.nextSibling.href; var rdmId = rdmHref.substr( rdmHref.lastIndexOf("=")+1,rdmHref.length );

revDelLinks[i].innerHTML += rdmId; newCheck.setAttribute( 'value', rdmId ); newCheck.setAttribute( 'class', 'revdelselect' ); newCheck.setAttribute( 'onClick', 'revDelToggle(this);' ); if (!rdmLinkA){ rdmLinkA = document.createElement('a'); rdmLinkA.setAttribute( 'href', rdmHref.substr(0,rdmHref.lastIndexOf('&')) ); rdmLinkA.setAttribute('title', 'Submit checked entries to Special:RevisionDelete'); rdmLinkA.innerHTML = 'show/hide'; }     } else { newCheck.disabled = true; }     revDelLinks[i].innerHTML = ''; revDelLinks[i].appendChild(newCheck); }   var firstForm = document.getElementsByTagName('form')[0]; if (firstForm){ rdmLinkS = document.createElement('a'); rdmLinkS.setAttribute( 'href', 'javascript:revDelSelect(true);' ); rdmLinkS.innerHTML = 'select all';

rdmLinkD = document.createTextNode('show/hide'); firstForm.parentNode.insertBefore( document.createTextNode(') '), firstForm.nextSibling );     if (rdmLinkA){	    firstForm.parentNode.insertBefore( rdmLinkS, firstForm.nextSibling );        firstForm.parentNode.insertBefore( document.createTextNode(' | '), firstForm.nextSibling );        firstForm.parentNode.insertBefore( rdmLinkA, firstForm.nextSibling );	  }	  firstForm.parentNode.insertBefore( rdmLinkD, firstForm.nextSibling );      firstForm.parentNode.insertBefore( document.createTextNode('('), firstForm.nextSibling ); rdmLinkA.innerHTML = ''; rdmSelectCt = 0; } } }

// Add or remove the entry ID function revDelToggle(rdmCheck) { if (wgPageName == "Special:Log") var rdmIdType = "&logid[]="; else var rdmIdType = "&oldid[]=";

var rdmStart = rdmLinkA.href.indexOf(rdmIdType + rdmCheck.value); var rdmEnd = rdmStart + (rdmIdType + rdmCheck.value).length; if (rdmCheck.checked && rdmStart == -1){ if ( rdmSelectCt++ == 0 ){ rdmLinkA.innerHTML = 'show/hide'; rdmLinkD.nodeValue = ''; } rdmLinkA.href += rdmIdType + rdmCheck.value; } else if(!rdmCheck.checked && rdmStart != -1){ if ( --rdmSelectCt == 0 ){ rdmLinkA.innerHTML = ''; rdmLinkD.nodeValue = 'show/hide'; } rdmLinkA.href = rdmLinkA.href.substring(0, rdmStart) + rdmLinkA.href.substring( rdmEnd, rdmLinkA.href.length ); } }

// Quickly check/uncheck selection checkboxes function revDelSelect(rdmOn) { var histOldIds = document.getElementsByName('oldid'), histOldId = 0; var histDiffIds = document.getElementsByName('diff'), histDiffId = 1000000000; for (var i in histOldIds) if (histOldIds[i].checked && i>1) histOldId = histOldIds[i].value; for (var i in histDiffIds) if (histDiffIds[i].checked) histDiffId = histDiffIds[i].value;

var revDelChecks = getElementsByClassName(document, "input", "revdelselect"); for (var i in revDelChecks){ if (revDelChecks[i].value > histOldId && revDelChecks[i].value < histDiffId) revDelChecks[i].checked = rdmOn; else revDelChecks[i].checked = false; revDelToggle(revDelChecks[i]); }

rdmLinkS.setAttribute( 'href', 'javascript:revDelSelect('+!rdmOn+');' ); rdmLinkS.innerHTML = (!rdmOn?'':'de')+'select all'; }

addOnloadHook(revDelMultiple);

// ================================================================== // End of RevisionDelete Multiple Entries // ==================================================================