User:逆襲的天邪鬼/MassUnimport.js

/* * Usage: After mw.loader.load('https://publictestwiki.com/w/index.php?title=User:逆襲的天邪鬼/MassUnimport.js&action=raw&ctype=text/javascript') *       Open Special:Log/import, check pages, and click "MassUnimport" on "More". */

$(function {    var massDelete = function (pages, reason, callback) {        var promises = [];        for (var i=0; i<pages.length; i++) {            promises.push($.ajax({                url: mw.util.wikiScript('api'),                data: {                    format: 'json',                    action: 'delete',                    title: pages[i],                    reason: reason,                    token: mw.user.tokens.get('editToken'),                },                dataType: 'json',                type: 'POST',            }));        }        $.when.apply($, promises).always(function  { if (typeof callback === 'function') { callback; }       });    };

if (mw.config.get('wgPageName') === 'Special:Log/import' || mw.config.get('wgPageName') === 'Special:日志/import' || ((mw.config.get('wgPageName') === 'Special:Log' || mw.config.get('wgPageName') === 'Special:日志') && mw.util.getParamValue('type') === 'import')) { var node = mw.util.addPortletLink('p-cactions', '#', 'MassUnimport'); $(node).click(function (e) {           e.preventDefault;

var checked = $('input[type=checkbox]', '.mw-logline-import').filter(function (index, e) { return e.checked; }); if (checked.length === 0) { alert('Please select at least one page.'); } else { var reason = prompt('Delete reason', 'Test done (by MassUnimport)'); if (reason !== null) { var pages = []; checked.each(function (index, e) {                       var title = $('.mw-usertoollinks + a[href^="/wiki/"]:last', e.parentElement).text;                        if (title) {                            pages.push(title);                        }                    }); massDelete(pages, reason, function {                        alert('done');                        history.go(0);                    }); }           }        });    } });