MediaWiki:Gadget-no-auto-autoblock.js

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索

注意:这类代码页面在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

$(function() {
    if (mw.config.get("wgCanonicalSpecialPageName") === "Block") {
        if ($("#mw-input-wpConfirm").val() === "") {
            $('input[name="wpAutoBlock"]').prop("checked", false);
        }
        var flag = false;
        var wpTarget = $('[name="wpTarget"]');
        var powerfulUserList = [];
        var submitButton = $('#mw-content-text [type="submit"]').parent();
        var submitButtonText = submitButton.text();
        submitButton.removeClass("oo-ui-widget-enabled oo-ui-flaggedElement-primary oo-ui-flaggedElement-progressive").addClass("oo-ui-widget-disabled").children().attr("disabled", "disabled").text("正在加载中……").closest("form").on("submit", function() {
            if (flag === false) {
                return false;
            }
            if (powerfulUserList.includes(wpTarget.val())) {
                return confirm("您要封禁的用户【" + wpTarget.val() + "】持有“封禁”和“自我解封”权限,您的封禁很可能无效且有可能违反封禁方针,您是否要继续?");
            }
        });
        new mw.Api({
            timeout: 5000
        }).post({
            action: "query",
            list: "allusers",
            aurights: "block|unblockself",
            aulimit: "max",
            auprop: "rights"
        }).then(function(result) {
            powerfulUserList = result.query.allusers.filter(function(au) {
                return au.rights.includes("block") && au.rights.includes("unblockself");
            }).map(function(au) {
                return au.name;
            });
            submitButton.addClass("oo-ui-widget-enabled oo-ui-flaggedElement-primary oo-ui-flaggedElement-progressive").removeClass("oo-ui-widget-disabled").children().removeAttr("disabled").text(submitButtonText);
            flag = true;
        }, function(error) {
            console.error(error);
            submitButton.after('<span class="error">无法获取持有“封禁”和“自我解封”权限的用户列表,请谨慎操作。</span>');
            submitButton.addClass("oo-ui-widget-enabled oo-ui-flaggedElement-primary oo-ui-flaggedElement-progressive").removeClass("oo-ui-widget-disabled").children().removeAttr("disabled").text(submitButtonText);
            flag = true;
        });
    }
});