“MediaWiki:Gadget-registerToDelete.js”的版本间的差异

来自萌娘共享
跳转至: 导航搜索
第2行: 第2行:
 
     var self = $('#p-cactions .menu ul');
 
     var self = $('#p-cactions .menu ul');
 
     if (!self.find('li')[0] || mw.config.get('wgUserGroups').indexOf('patroller') === -1) return;
 
     if (!self.find('li')[0] || mw.config.get('wgUserGroups').indexOf('patroller') === -1) return;
     $('<a/>', {
+
     if (mw.config.get('wgAction') === 'edit' && decodeURIComponent((/preloadText=[^\&]+/.exec(location.search) || [''])[0])) $('#wpTextbox1').val(decodeURIComponent((/preloadText=[^\&]+/.exec(location.search) || [''])[0]));
 +
    else if (mw.config.get('wgAction') !== 'submit') $('<a/>', {
 
         attr: {
 
         attr: {
 
             href: "#",
 
             href: "#",
第8行: 第9行:
 
             accesskey: 'd'
 
             accesskey: 'd'
 
         },
 
         },
         text:'挂删'
+
         text: '挂删'
 
     }).on('click', function() {
 
     }).on('click', function() {
 
         var reason = prompt('挂删的理由【将会替换全文内容】\n【空白则使用默认理由(不在收录范围内或潜在价值较低)】\n【取消则不进行挂删】:'),
 
         var reason = prompt('挂删的理由【将会替换全文内容】\n【空白则使用默认理由(不在收录范围内或潜在价值较低)】\n【取消则不进行挂删】:'),
 
             self = $(this);
 
             self = $(this);
 
         if (reason === null) return;
 
         if (reason === null) return;
         var loadingPic = $('<div/>', {
+
         windows.open(location.origin + location.pathname + (location.search || '?action=edit') + '&preloadText={{即将删除|' + reason + '}}', '_blank');
                css: {
+
     });
                    position: 'fixed',
 
                    top: '0',
 
                    left: '0',
 
                    height: '100vh',
 
                    width: '100vw',
 
                    transition: 'all .73s linear',
 
                    color: 'black',
 
                    'padding-top':'49vh',
 
                    'background-color': 'rgba(255,255,255,0.73)',
 
                    'text-align': 'center'
 
                }
 
            }).append('<img src="https://common.moegirl.org/extensions/FancyBoxThumbs/modules/fancyBox/source/fancybox_loading.gif" />正在挂删中……'),
 
            reasonText = reason ? '|' + reason : '';
 
        $.ajax({
 
            url: 'https://common.moegirl.org/api.php?action=query&meta=tokens&format=json',
 
            type: 'GET',
 
            beforeSend: function() {
 
                $(document.body).append(loadingPic);
 
            },
 
            error: function() {
 
                loadingPic.css('color', 'red').text('挂删失败……').delay(1000).queue(function() {
 
                    $(this).fadeOut(370);
 
                    $(this).dequeue();
 
                });
 
            },
 
            success: function(d) {
 
                if (d.error) return loadingPic.css('color', 'red').text('挂删失败……').delay(1000).queue(function() {
 
                    $(this).fadeOut(370);
 
                    $(this).dequeue();
 
                });
 
                var token = d.query.tokens.csrftoken;
 
                $.ajax({
 
                    url: 'https://common.moegirl.org/api.php',
 
                    type: 'POST',
 
                    data: {
 
                        action: 'edit',
 
                        format: 'json',
 
                        title: mw.config.get('wgPageName'),
 
                        text: '{{即将删除' + reasonText + '}}',
 
                        summary: '挂删' + (reason ? ':' + reason : ''),
 
                        nocreate: true,
 
                        watchlist: 'preferences',
 
                        token: token
 
                    },
 
                    error: function() {
 
                        loadingPic.css('color', 'red').text(' 挂删失败……').delay(1000).queue(function() {
 
                            $(this).fadeOut(370);
 
                            $(this).dequeue();
 
                        });
 
                    },
 
                    success: function(d) {
 
                        if (d.error) return loadingPic.css('color', 'red').text('挂删失败……').delay(1000).queue(function() {
 
                            $(this).fadeOut(370);
 
                            $(this).dequeue();
 
                        });
 
                        loadingPic.css('color', 'green').text('挂删成功!即将刷新……');
 
                        window.setTimeout(function(){
 
                            window.location.reload();
 
                        }, 730);
 
                    }
 
                });
 
            }
 
        });
 
     }).appendTo($('<li/>', {
 
        attr: {
 
            id: 'ca-registerToDelete'
 
        }
 
    }).prependTo(self));
 
 
});
 
});

2016年12月14日 (三) 23:22的版本

$(function() {
    var self = $('#p-cactions .menu ul');
    if (!self.find('li')[0] || mw.config.get('wgUserGroups').indexOf('patroller') === -1) return;
    if (mw.config.get('wgAction') === 'edit' && decodeURIComponent((/preloadText=[^\&]+/.exec(location.search) || [''])[0])) $('#wpTextbox1').val(decodeURIComponent((/preloadText=[^\&]+/.exec(location.search) || [''])[0]));
    else if (mw.config.get('wgAction') !== 'submit') $('<a/>', {
        attr: {
            href: "#",
            title: "挂删本页[alt-shift-d]",
            accesskey: 'd'
        },
        text: '挂删'
    }).on('click', function() {
        var reason = prompt('挂删的理由【将会替换全文内容】\n【空白则使用默认理由(不在收录范围内或潜在价值较低)】\n【取消则不进行挂删】:'),
            self = $(this);
        if (reason === null) return;
        windows.open(location.origin + location.pathname + (location.search || '?action=edit') + '&preloadText={{即将删除|' + reason + '}}', '_blank');
    });
});