Jump to content

User:Anomie/revdel-checkboxes.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Anomie (talk | contribs) at 20:22, 18 February 2012 (moved User:Anomie/file-revdel-checkboxes.js to User:Anomie/revdel-checkboxes.js: Expanding to log entries, so former name was no longer correct). 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.
$(document).ready(function(){
    var ct=0;
    $('.filehistory .mw-revdelundel-link a').each(function(i,a){
        var m=a.href.match(/&ids=([0-9]+)/);
        if(!m) return;
        var chk=$('<input type="checkbox" name="revdel-ids" value="'+m[1]+'" />');
        var td=a;
        while(td.nodeName!='TD') td=td.parentNode;
        chk.appendTo(td);
        ct++;
    });
    if(ct<=0) return;

    var button=$('<input type="button" value="Del/undel selected" />');
    button.click(function(ev){
        var q={
            title:'Special:RevisionDelete',
            type:'oldimage',
            target:mw.config.get('wgPageName'),
            ids:{}
        };
        var ct=0;
        $('input[name="revdel-ids"]').each(function(i,n){
            if(n.checked){
                ct++;
                q.ids[n.value]=1;
            }
        });
        if(ct == 0) $('input[name="revdel-ids"]').each(function(i,n){
            ct++;
            q.ids[n.value]=1;
        });
        if(ct > 0) location.href=mw.config.get('wgScript')+'?'+jQuery.param(q);
    });
    $('.filehistory').after(button);
});