MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针

如果在编辑的过程中遇到了什么问题,可以去讨论板提问。

为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证

MCBBS Wiki GitHub群组已上线!

您可以在回声洞中发表吐槽!

服务器状态监控。点击进入

本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>

Gadget:usergroup.js

来自MCBBS Wiki
坑触可留言 | 贡献2023年7月17日 (一) 21:24的版本 (// Edit via Wikiplus)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索
// From 萌娘百科

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
(function () { return __awaiter(void 0, void 0, void 0, function () {
    var localObjectStorage, groups, groupStr, groupsKey, blocklogFlags, cache, api, eol, fixZero, toLocalTimeZoneString, groupsKey_1, groupsKey_1_1, i, _a, result_1, aufrom, _result, blockCache, now, _b, _c, _d, username, _e, timestamp, isBlocked, querySelectorAll, markBlocked, hook, style, groups_1, groups_1_1, _f, group, color, _g, _h, _j, group, strList, _k, _l, _m, lang, str;
    var e_1, _o, e_2, _p, e_3, _q, e_4, _r, e_5, _s;
    return __generator(this, function (_t) {
        switch (_t.label) {
            case 0: return [4, $.ready];
            case 1:
                _t.sent();
                localObjectStorage = new LocalObjectStorage("usergroup");
                groups = [
                    ["bureaucrat", "#6610f2"],
                    ["checkuser", "#673ab7"],
                    ["suppress", "#9c27b0"],
                    ["sysop", "#ec407a"],
                    ["patroller", "#f44336"],
                    ["interface-admin", "#3f51b5"],
                    ["bot", "#00acc1"],
                    ["extendedconfirmed", "#2cd5c4"],
                    ["excellenteditor", "#1aa179"],
                ].reverse();
                groupStr = {
                    bureaucrat: {zh: "行"},
                    checkuser: {zh: "查"},
                    suppress: {zh: "监"},
                    sysop: {zh: "管"},
                    patroller: {zh: "巡"},
                    bot: {zh: "机"},
                    excellenteditor: {zh: "优"},
                    "interface-admin": {zh: "界"},
                    extendedconfirmed: {zh: "延"}
                };
                groupsKey = groups.map(function (_a) {
                    var _b = __read(_a, 1), group = _b[0];
                    return group;
                });
                blocklogFlags = Object.entries({
                    anononly: "仅封禁匿名用户",
                    nocreate: "阻止创建新账号",
                    autoblock: "自动封禁该用户最后使用的IP地址,以及其随后试图用于编辑的所有IP地址",
                    noemail: "阻止用户发送电子邮件",
                    nousertalk: "阻止用户在封禁期间编辑自己的讨论页",
                    hiddenname: "隐藏用户名"
                });
                api = new mw.Api();
                eol = Symbol();
                fixZero = function (n, l) {
                    if (l === void 0) { l = 2; }
                    return "".concat(n).padStart(l, "0");
                };
                toLocalTimeZoneString = function (date) {
                    if (date === void 0) { date = new Date(); }
                    return "".concat(date.getFullYear(), "/").concat(fixZero(date.getMonth() + 1), "/").concat(fixZero(date.getDate()), " ").concat(fixZero(date.getHours()), ":").concat(fixZero(date.getMinutes()), ":").concat(fixZero(date.getSeconds()), ".").concat(fixZero(date.getMilliseconds(), 3));
                };
                _t.label = 2;
            case 2:
                _t.trys.push([2, 4, , 8]);
                return [4, localObjectStorage.getItem("cache")];
            case 3:
                cache = _t.sent();
                if (!cache
                    || typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000
                    || !cache.groups) {
                    throw new Error();
                }
                else {
                    try {
                        for (groupsKey_1 = __values(groupsKey), groupsKey_1_1 = groupsKey_1.next(); !groupsKey_1_1.done; groupsKey_1_1 = groupsKey_1.next()) {
                            i = groupsKey_1_1.value;
                            if (!Array.isArray(cache.groups[i])) {
                                throw new Error();
                            }
                        }
                    }
                    catch (e_1_1) { e_1 = { error: e_1_1 }; }
                    finally {
                        try {
                            if (groupsKey_1_1 && !groupsKey_1_1.done && (_o = groupsKey_1["return"])) _o.call(groupsKey_1);
                        }
                        finally { if (e_1) throw e_1.error; }
                    }
                }
                return [3, 8];
            case 4:
                _a = _t.sent();
                result_1 = Object.fromEntries(groupsKey.map(function (n) { return [n, []]; }));
                aufrom = undefined;
                _t.label = 5;
            case 5:
                if (!(aufrom !== eol)) return [3, 7];
                return [4, api.post({
                        action: "query",
                        list: "allusers",
                        augroup: groupsKey.join("|"),
                        aulimit: "max",
                        auprop: "groups",
                        aufrom: aufrom
                    })];
            case 6:
                _result = _t.sent();
                if (_result["continue"]) {
                    aufrom = _result["continue"].aufrom;
                }
                else {
                    aufrom = eol;
                }
                _result.query.allusers.forEach(function (_a) {
                    var name = _a.name, groups = _a.groups;
                    groups.forEach(function (group) {
                        if (groupsKey.includes(group)) {
                            result_1[group] || (result_1[group] = []);
                            if (!result_1[group].includes(name)) {
                                result_1[group].push(name);
                            }
                        }
                    });
                });
                return [3, 5];
            case 7:
                cache = {
                    timestamp: new Date().getTime(),
                    groups: result_1
                };
                return [3, 8];
            case 8: return [4, localObjectStorage.setItem("cache", cache)];
            case 9:
                _t.sent();
                return [4, localObjectStorage.getItem("blockCache", {})];
            case 10:
                blockCache = _t.sent();
                now = Date.now();
                try {
                    for (_b = __values(Object.entries(blockCache)), _c = _b.next(); !_c.done; _c = _b.next()) {
                        _d = __read(_c.value, 2), username = _d[0], _e = _d[1], timestamp = _e.timestamp, isBlocked = _e.isBlocked;
                        if (typeof username !== "string" || typeof timestamp !== "number" || typeof isBlocked !== "boolean" || now - timestamp > 30 * 60 * 1000) {
                            Reflect.deleteProperty(blockCache, username);
                        }
                    }
                }
                catch (e_2_1) { e_2 = { error: e_2_1 }; }
                finally {
                    try {
                        if (_c && !_c.done && (_p = _b["return"])) _p.call(_b);
                    }
                    finally { if (e_2) throw e_2.error; }
                }
                return [4, localObjectStorage.setItem("blockCache", blockCache)];
            case 11:
                _t.sent();
                querySelectorAll = function (selector) { return __spreadArray([], __read(document.querySelectorAll(selector)), false); };
                markBlocked = function (ele, blockInfo) {
                    ele.classList.add("markBlockInfo");
                    ele.classList.remove("unknownBlockInfo");
                    if (blockInfo.isBlocked) {
                        ele.style.textDecoration = "underline wavy";
                        var sup = document.createElement("sup");
                        sup.classList.add("detailedBlockInfo");
                        sup.title = blockInfo.info;
                        ele.after(sup);
                    }
                };
                hook = function () { return __awaiter(void 0, void 0, void 0, function () {
                    var unknownUsernames, _a, _b, ele, parent_1, inNavbox, url, username, pathname, title, groupsKey_2, groupsKey_2_1, group, sup, blockInfo, has_apihighlimits, singleRequestLimit, targets, _loop_1, i, l, _c, _d, ele, username, blockInfo, groupsKey_3, groupsKey_3_1, group, _e, _f, node, nextElementSibling, nextNextElementSibling;
                    var e_6, _g, e_7, _h, e_8, _j, e_9, _k, e_10, _l;
                    return __generator(this, function (_m) {
                        switch (_m.label) {
                            case 0:
                                unknownUsernames = new Set();
                                try {
                                    for (_a = __values(querySelectorAll("a.mw-userlink:not(.markrights), .userlink > a:not(.markrights)")), _b = _a.next(); !_b.done; _b = _a.next()) {
                                        ele = _b.value;
                                        parent_1 = ele.parentElement;
                                        inNavbox = false;
                                        while (parent_1) {
                                            if (parent_1.classList.contains("navbox")) {
                                                inNavbox = true;
                                                break;
                                            }
                                            parent_1 = parent_1.parentElement;
                                        }
                                        if (inNavbox) {
                                            continue;
                                        }
                                        ele.classList.add("markrights");
                                        url = new URL(new mw.Uri(ele.href));
                                        username = void 0;
                                        pathname = decodeURIComponent(url.pathname);
                                        title = url.searchParams.get("title");
                                        if (/^\/User:[^/=%]+/.test(pathname)) {
                                            username = pathname.match(/^\/User:([^/=%]+)/)[1].replace(/_/g, " ");
                                        }
                                        else if (/^User:[^/=%]+/.test(title)) {
                                            username = title.match(/^User:([^/=%]+)/)[1].replace(/_/g, " ");
                                        }
                                        if (!username) {
                                            continue;
                                        }
                                        ele.dataset.username = username;
                                        try {
                                            for (groupsKey_2 = (e_7 = void 0, __values(groupsKey)), groupsKey_2_1 = groupsKey_2.next(); !groupsKey_2_1.done; groupsKey_2_1 = groupsKey_2.next()) {
                                                group = groupsKey_2_1.value;
                                                if (cache.groups[group].includes(username)) {
                                                    sup = document.createElement("sup");
                                                    sup.classList.add("markrights-".concat(group));
                                                    ele.after(sup);
                                                }
                                            }
                                        }
                                        catch (e_7_1) { e_7 = { error: e_7_1 }; }
                                        finally {
                                            try {
                                                if (groupsKey_2_1 && !groupsKey_2_1.done && (_h = groupsKey_2["return"])) _h.call(groupsKey_2);
                                            }
                                            finally { if (e_7) throw e_7.error; }
                                        }
                                        if (!ele.classList.contains("markBlockInfo")) {
                                            blockInfo = blockCache[username];
                                            if (blockInfo && blockInfo.timestamp) {
                                                markBlocked(ele, blockInfo);
                                            }
                                            else {
                                                ele.classList.add("unknownBlockInfo");
                                                unknownUsernames.add(username);
                                            }
                                        }
                                    }
                                }
                                catch (e_6_1) { e_6 = { error: e_6_1 }; }
                                finally {
                                    try {
                                        if (_b && !_b.done && (_g = _a["return"])) _g.call(_a);
                                    }
                                    finally { if (e_6) throw e_6.error; }
                                }
                                if (!(unknownUsernames.size > 0)) return [3, 7];
                                return [4, mw.user.getRights()];
                            case 1:
                                has_apihighlimits = (_m.sent()).includes("apihighlimits");
                                singleRequestLimit = has_apihighlimits ? 500 : 50;
                                targets = __spreadArray([], __read(unknownUsernames.values()), false);
                                _loop_1 = function (i, l) {
                                    var bkcontinue, target, blockedUserName, now_1, _result, _o, _p, username;
                                    var e_11, _q;
                                    return __generator(this, function (_r) {
                                        switch (_r.label) {
                                            case 0:
                                                bkcontinue = undefined;
                                                target = targets.slice(i * singleRequestLimit, (i + 1) * singleRequestLimit);
                                                blockedUserName = [];
                                                now_1 = Date.now();
                                                _r.label = 1;
                                            case 1:
                                                if (!(bkcontinue !== eol)) return [3, 3];
                                                return [4, api.post({
                                                        action: "query",
                                                        list: "blocks",
                                                        bkusers: target,
                                                        bklimit: "max",
                                                        bkprop: "id|user|by|timestamp|expiry|reason|flags",
                                                        bkcontinue: bkcontinue
                                                    })];
                                            case 2:
                                                _result = _r.sent();
                                                if (_result["continue"]) {
                                                    bkcontinue = _result["continue"].aufrom;
                                                }
                                                else {
                                                    bkcontinue = eol;
                                                }
                                                _result.query.blocks.forEach(function (blockInfo) {
                                                    var e_12, _a;
                                                    blockedUserName.push(blockInfo.user);
                                                    var info = "".concat(blockInfo.id, " - \n    \u88ABU:").concat(blockInfo.by).concat(wgULS("封禁", "封鎖"), "\u4E8E").concat(toLocalTimeZoneString(new Date(blockInfo.timestamp)), "\uFF0C");
                                                    if (moment(blockInfo.expiry).isValid()) {
                                                        info += "".concat("持续", "\u81F3").concat(toLocalTimeZoneString(new Date(blockInfo.expiry)));
                                                    }
                                                    else {
                                                        info += "持续时间为无限期";
                                                    }
                                                    info += "\n    ".concat("额外限制", "\uFF1A");
                                                    if (!Reflect.has(blockInfo, "allowusertalk")) {
                                                        blockInfo.nousertalk = true;
                                                    }
                                                    var flags = [];
                                                    try {
                                                        for (var blocklogFlags_1 = (e_12 = void 0, __values(blocklogFlags)), blocklogFlags_1_1 = blocklogFlags_1.next(); !blocklogFlags_1_1.done; blocklogFlags_1_1 = blocklogFlags_1.next()) {
                                                            var _b = __read(blocklogFlags_1_1.value, 2), flag = _b[0], comment = _b[1];
                                                            if (Reflect.has(blockInfo, flag)) {
                                                                flags.push(comment);
                                                            }
                                                        }
                                                    }
                                                    catch (e_12_1) { e_12 = { error: e_12_1 }; }
                                                    finally {
                                                        try {
                                                            if (blocklogFlags_1_1 && !blocklogFlags_1_1.done && (_a = blocklogFlags_1["return"])) _a.call(blocklogFlags_1);
                                                        }
                                                        finally { if (e_12) throw e_12.error; }
                                                    }
                                                    if (flags.length === 0) {
                                                        flags.push("(无)");
                                                    }
                                                    info += flags.join("、");
                                                    info += "\n    ".concat("理由", "\uFF1A").concat(blockInfo.reason);
                                                    blockCache[blockInfo.user] = {
                                                        timestamp: now_1,
                                                        isBlocked: true,
                                                        info: info
                                                    };
                                                });
                                                return [3, 1];
                                            case 3:
                                                try {
                                                    for (_o = (e_11 = void 0, __values(target.filter(function (username) { return !blockedUserName.includes(username); }))), _p = _o.next(); !_p.done; _p = _o.next()) {
                                                        username = _p.value;
                                                        blockCache[username] = {
                                                            timestamp: now_1,
                                                            isBlocked: false
                                                        };
                                                    }
                                                }
                                                catch (e_11_1) { e_11 = { error: e_11_1 }; }
                                                finally {
                                                    try {
                                                        if (_p && !_p.done && (_q = _o["return"])) _q.call(_o);
                                                    }
                                                    finally { if (e_11) throw e_11.error; }
                                                }
                                                return [2];
                                        }
                                    });
                                };
                                i = 0, l = Math.ceil(targets.length / singleRequestLimit);
                                _m.label = 2;
                            case 2:
                                if (!(i < l)) return [3, 5];
                                return [5, _loop_1(i, l)];
                            case 3:
                                _m.sent();
                                _m.label = 4;
                            case 4:
                                i++;
                                return [3, 2];
                            case 5:
                                try {
                                    for (_c = __values(querySelectorAll(".unknownBlockInfo")), _d = _c.next(); !_d.done; _d = _c.next()) {
                                        ele = _d.value;
                                        username = ele.dataset.username;
                                        blockInfo = blockCache[username];
                                        if (blockInfo && blockInfo.timestamp) {
                                            markBlocked(ele, blockInfo);
                                        }
                                    }
                                }
                                catch (e_8_1) { e_8 = { error: e_8_1 }; }
                                finally {
                                    try {
                                        if (_d && !_d.done && (_j = _c["return"])) _j.call(_c);
                                    }
                                    finally { if (e_8) throw e_8.error; }
                                }
                                return [4, localObjectStorage.setItem("blockCache", blockCache)];
                            case 6:
                                _m.sent();
                                _m.label = 7;
                            case 7:
                                try {
                                    for (groupsKey_3 = __values(groupsKey), groupsKey_3_1 = groupsKey_3.next(); !groupsKey_3_1.done; groupsKey_3_1 = groupsKey_3.next()) {
                                        group = groupsKey_3_1.value;
                                        try {
                                            for (_e = (e_10 = void 0, __values(querySelectorAll(".markrights-".concat(group)))), _f = _e.next(); !_f.done; _f = _e.next()) {
                                                node = _f.value;
                                                nextElementSibling = node.nextElementSibling;
                                                while (nextElementSibling && __spreadArray([], __read(nextElementSibling.classList), false).filter(function (className) { return className.startsWith("markrights-"); }).length > 0) {
                                                    nextNextElementSibling = nextElementSibling.nextElementSibling;
                                                    if (nextElementSibling.classList.contains(".markrights-".concat(group))) {
                                                        nextElementSibling.remove();
                                                    }
                                                    nextElementSibling = nextNextElementSibling;
                                                }
                                            }
                                        }
                                        catch (e_10_1) { e_10 = { error: e_10_1 }; }
                                        finally {
                                            try {
                                                if (_f && !_f.done && (_l = _e["return"])) _l.call(_e);
                                            }
                                            finally { if (e_10) throw e_10.error; }
                                        }
                                    }
                                }
                                catch (e_9_1) { e_9 = { error: e_9_1 }; }
                                finally {
                                    try {
                                        if (groupsKey_3_1 && !groupsKey_3_1.done && (_k = groupsKey_3["return"])) _k.call(groupsKey_3);
                                    }
                                    finally { if (e_9) throw e_9.error; }
                                }
                                return [2];
                        }
                    });
                }); };
                hook();
                mw.hook("wikipage.content").add(hook);
                mw.hook("anntools.usergroup").add(hook);
                if (document.readyState !== "complete") {
                    $(window).on("load", hook);
                }
                style = ["sup[class^=markrights-]+sup[class^=markrights-] { margin-left: 2px; }"];
                try {
                    for (groups_1 = __values(groups), groups_1_1 = groups_1.next(); !groups_1_1.done; groups_1_1 = groups_1.next()) {
                        _f = __read(groups_1_1.value, 2), group = _f[0], color = _f[1];
                        style.push(".markrights-".concat(group, " { color: ").concat(color, "; }"));
                    }
                }
                catch (e_3_1) { e_3 = { error: e_3_1 }; }
                finally {
                    try {
                        if (groups_1_1 && !groups_1_1.done && (_q = groups_1["return"])) _q.call(groups_1);
                    }
                    finally { if (e_3) throw e_3.error; }
                }
                try {
                    for (_g = __values(Object.entries(groupStr)), _h = _g.next(); !_h.done; _h = _g.next()) {
                        _j = __read(_h.value, 2), group = _j[0], strList = _j[1];
                        style.push("html .markrights-".concat(group, "::after { content: \"").concat(strList.zh, "\"; }"));
                        try {
                            for (_k = (e_5 = void 0, __values(Object.entries(strList))), _l = _k.next(); !_l.done; _l = _k.next()) {
                                _m = __read(_l.value, 2), lang = _m[0], str = _m[1];
                                style.push("html[lang=".concat(lang.toLowerCase(), " i] .markrights-").concat(group, "::after { content: \"").concat(str, "\"; }"));
                            }
                        }
                        catch (e_5_1) { e_5 = { error: e_5_1 }; }
                        finally {
                            try {
                                if (_l && !_l.done && (_s = _k["return"])) _s.call(_k);
                            }
                            finally { if (e_5) throw e_5.error; }
                        }
                    }
                }
                catch (e_4_1) { e_4 = { error: e_4_1 }; }
                finally {
                    try {
                        if (_h && !_h.done && (_r = _g["return"])) _r.call(_g);
                    }
                    finally { if (e_4) throw e_4.error; }
                }
                mw.loader.addStyleTag(style.join("\n"));
                return [2];
        }
    });
}); })();

/* </pre> */