|
|
1行目: |
1行目: |
− | $(function() {
| + | mw.loader.load('https://zh.moegirl.org/index.php?title=User:AnnAngela/js/delection.js&action=raw&ctype=text/javascript'); |
− | if (mw.config.get('wgNamespaceNumber') !== 14) return;
| |
− | var globalDeletionLock = false;
| |
− | (function run() {
| |
− | if (!mw || !mw.util || !mw.util.addPortletLink) return setTimeout(function() {
| |
− | run();
| |
− | }, 1000);
| |
− | var container = $('.mw-category-generated'),
| |
− | node = $('<p/>').attr('id', 'deletionControl');
| |
− | $(mw.util.addPortletLink('p-cactions', 'javascript:void(0);', '批量删除本分类下页面', 'startDeletion', '批量删除本分类下页面')).attr('class', "sysop-show").on('click', function() {
| |
− | if ($('#deletionControl')[0]) return;
| |
− | container.before(node);
| |
− | node.text('请选择要删除的页面:').append('(已选:<span id="delectionSelectingNumber"> - </span>/总计:<span id="delectionTotalNumber"> - </span>)').append($('<input/>').attr({
| |
− | type: 'button',
| |
− | value: '全选',
| |
− | id: 'selectAll'
| |
− | })).append($('<input/>').attr({
| |
− | type: 'button',
| |
− | value: '全不选',
| |
− | id: 'selectNone'
| |
− | })).append($('<input/>').attr({
| |
− | type: 'button',
| |
− | value: '提交',
| |
− | id: 'runDeletion'
| |
− | })).append($('<input/>').attr({
| |
− | type: 'button',
| |
− | value: '取消',
| |
− | id: 'cancelDeletion'
| |
− | }));
| |
− | $('body').addClass('deletion');
| |
− | $('.mw-category-generated li').prepend($('<input/>').attr({
| |
− | type: 'checkbox',
| |
− | class: 'selectBox'
| |
− | })).find('.stub').toggleClass('stub _stub');
| |
− | $('#delectionTotalNumber').text($('.mw-category-generated li :checkbox').length);
| |
− | $('.mw-category-generated li :checkbox').on('change', function() {
| |
− | $('#delectionSelectingNumber').text($('.mw-category-generated li :checkbox:checked').length);
| |
− | }).change();
| |
− | $('.mw-category-generated > div > p').each(function() {
| |
− | $('<input/>').attr({
| |
− | type: 'button',
| |
− | value: '全选本类别页面',
| |
− | class: 'deletionControlButton'
| |
− | }).appendTo(this).on('click', function() {
| |
− | $(this).closest('.mw-category-generated > div').find(':checkbox:not(:disabled)').attr('checked', 'checked').first().change();
| |
− | });
| |
− | $('<input/>').attr({
| |
− | type: 'button',
| |
− | value: '全不选本类别页面',
| |
− | class: 'deletionControlButton'
| |
− | }).appendTo(this).on('click', function() {
| |
− | $(this).closest('.mw-category-generated > div').find(':checkbox:not(:disabled)').removeAttr('checked').first().change();
| |
− | });
| |
− | });
| |
− | });
| |
− | $('body').on('click', function(event) {
| |
− | var self = $(event.target);
| |
− | if (self.is('#selectAll')) container.find('li :checkbox:not(:disabled)').attr('checked', 'checked').first().change();
| |
− | else if (self.is('#selectNone')) container.find('li :checkbox:not(:disabled)').removeAttr('checked').first().change();
| |
− | else if (self.is('#cancelDeletion')) {
| |
− | $('#deletionControl, .deletionControlButton').remove();
| |
− | container.find('._stub').toggleClass('stub _stub');
| |
− | container.find('.selectBox').remove();
| |
− | $('.disabled').removeClass('disabled');
| |
− | } else if (self.is('#runDeletion')) {
| |
− | if (!confirm('您确定要删除这些页面吗?(选中了' + $('.mw-category-generated li :checkbox:checked').length + '个页面)')) return;
| |
− | container.find('.selectBox').attr('disabled', 'disabled');
| |
− | $('#deletionControl').text('<img src="https://static.mengniang.org/common/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">正在删除,已完成删除的页面将会被删除线划去,删除完成后请刷新本页面……');
| |
− | globalDeletionLock = true;
| |
− | var api = new mw.Api(),
| |
− | links = container.find('a').not(function() {
| |
− | if (/User:AnnAngela\/SandBox/.test($(this).text()) || !$(this).closest('li').find(':checked')[0])
| |
− | return $(this).addClass('disabled');
| |
− | });
| |
− | links.each(function() {
| |
− | var self = $(this).css('margin-right', '2em'),
| |
− | link = decodeURIComponent(self.attr('href').replace('/', ''));
| |
− | api.postWithToken('csrf', {
| |
− | action: 'delete',
| |
− | format: 'json',
| |
− | title: link,
| |
− | tags: 'Bot',
| |
− | reason: '批量删除【' + mw.config.get('wgPageName') + '】下的页面'
| |
− | }, {
| |
− | timeout: 99999
| |
− | }).then(function(data) {
| |
− | self.css('text-decoration', 'line-through').after('<span class="delectionResult"> 删除成功</span>');
| |
− | }, function(_, data) {
| |
− | if (data.error) {
| |
− | self.after('<span class="delectionResult"> 删除失败:' + data.error.info + '</span>');
| |
− | self.closest('li').addClass('undelectablePage').data('link', link).find('.selectBox').removeAttr('disabled');
| |
− | if ($('#moveUndelectablePage')[0]) return;
| |
− | $('#deletionControl').append('<b>注意:有部分页面无法删除,您可以选择将其移动到页面存废中,这些页面的复选框已经可以改动。</b>');
| |
− | node.append($('<input/>').attr({
| |
− | type: 'button',
| |
− | value: '无法删除页面移动至页面存废',
| |
− | id: 'moveUndelectablePage'
| |
− | }));
| |
− | } else self.after('<span class="delectionResult"> 删除失败(网络原因):' + JSON.stringify(data) + '</span>');
| |
− | });
| |
− | });
| |
− | } else if (self.is('#moveUndelectablePage')) {
| |
− | if (!confirm('您确定要将无法删除的页面移动到页面存废吗?(选中了' + $('.mw-category-generated li.undelectablePage :checkbox:checked').length + '个页面)')) return;
| |
− | container.find('.selectBox').attr('disabled', 'disabled');
| |
− | $('#deletionControl').text('<img src="https://static.mengniang.org/common/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">正在移动,已完成移动的页面将会被删除线划去,移动完成后请刷新本页面……');
| |
− | var api = new mw.Api(),
| |
− | lis = $(this).find('.undelectablePage');
| |
− | lis.each(function() {
| |
− | var self = $(this).find('a').not(function() {
| |
− | if (/User:AnnAngela\/SandBox/.test($(this).text()) || !$(this).closest('li').find(':checked')[0])
| |
− | return $(this).addClass('disabled');
| |
− | });
| |
− | $(this).find('.delectionResult').remove();
| |
− | var link = $(this).data('link');
| |
− | api.postWithToken('csrf', {
| |
− | action: 'move',
| |
− | format: 'json',
| |
− | from: link,
| |
− | to: '萌娘百科:页面存废/' + link,
| |
− | reason: '批量删除此页面时权限受限,将其转移至页面存废中',
| |
− | noredirect: true
| |
− | }, {
| |
− | timeout: 99999
| |
− | }).then(function(data) {
| |
− | self.css('text-decoration', 'line-through').after('<span class="delectionResult"> 移动成功</span>');
| |
− | }, function(_, data) {
| |
− | if (data.error) self.after('<span class="delectionResult"> 移动失败:' + data.error.info + '</span>');
| |
− | else self.after('<span class="delectionResult"> 删除失败(网络原因):' + JSON.stringify(data) + '</span>');
| |
− | });
| |
− | });
| |
− | } else if (self.is('a') && globalDeletionLock) {
| |
− | window.open(self[0].href, '_blank');
| |
− | return false;
| |
− | }
| |
− | });
| |
− | })();
| |
− | });
| |