User:C8H17OH/registerToDelete.js

From Moegirlpedia
< User:C8H17OH
Revision as of 06:13, 14 August 2020 by C8H17OH (talk | contribs) (Created page with "// Register-to-delete tool for EnMGP, modified from zhmoe:MediaWiki:Gadget-registerToDelete.js // Alert: only able/allowed to use by patrollers or higher authority // Note...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// Register-to-delete tool for EnMGP, modified from [[zhmoe:MediaWiki:Gadget-registerToDelete.js]]
// Alert: only able/allowed to use by patrollers or higher authority
// Note: instructions are not translated totally
// Usage: add the following code in [[Special:MyPage/common.js]]: mw.loader.load('https://en.moegirl.org.cn/index.php?title=User:C8H17OH/registerToDelete.js&action=raw&ctype=text/javascript');

// <pre>
$(function() {
    var self = $('#p-cactions .menu ul');
    if (!self.find('li')[0] || $('.willBeDeleted')[0] || mw.config.get('wgUserGroups').indexOf('patroller') === -1) return;
    $('<a/>', {
        attr: {
            href: "#",
            title: "挂删本页[alt-shift-d]",
            accesskey: 'd'
        },
        text: '挂删'
    }).on('click', function() {
        var reason = prompt('挂删的理由【将会替换全文内容】\n【空白则使用默认理由(Out of coverage or low potential value)】\n【取消则不进行挂删】:'),
            self = $(this);
        if (reason === null) return;
        if (reason === '') reason = 'Out of coverage or low potential value';
        var loadingBox = $('<div/>', {
                css: {
                    position: 'fixed',
                    top: '0',
                    left: '0',
                    height: '100vh',
                    width: '100vw',
                    transition: 'opacity .73s linear',
                    color: 'black',
                    'padding-top': '49vh',
                    'background-color': 'rgba(255,255,255,0.73)',
                    'text-align': 'center'
                }
            }).append('<img src="https://static.mengniang.org/common/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">正在挂删中……'),
            reasonText = reason ? '|' + reason : '',
            api = new mw.Api();
        loadingBox.endOut = function endOut() {
            this.css('color', 'red').text('挂删失败……').delay(1000).queue(function() {
                $(this).css('opacity', '0').delay(730).queue(function() {
                    $(this).remove();
                    $(document.body).css('overflow', 'auto');
                    $(this).dequeue();
                });
                $(this).dequeue();
            });
        };
        $(document.body).append(loadingBox).css('overflow', 'hidden');
        api.postWithToken('csrf', {
            action: 'edit',
            format: 'json',
            title: mw.config.get('wgPageName'),
            text: '<noinclude>{{Awaiting deletion' + reasonText + '|user=' + mw.config.get("wgUserName") + '}}</noinclude>',
            summary: 'Register to delete:' + reason,
            nocreate: true,
            watchlist: 'preferences'
        }).then(function(d) {
            if (d.error) return loadingBox.endOut();
            loadingBox.css('color', 'green').text('挂删成功!即将刷新……');
            window.setTimeout(function() {
                window.location.reload();
            }, 730)
        }, loadingBox.endOut.bind(loadingBox));
    }).appendTo($('<li/>', {
        attr: {
            id: 'ca-registerToDelete'
        }
    }).prependTo(self));
});
// </pre>