2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

MediaWiki:Gadget-SpecialWikitext.js

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索

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

  • Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
  • Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
  • Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
  • Opera:在“工具→首选项”中清除缓存
如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码?_=1来访问最新页面。
添加代码后的本页地址如下:-{R|https://moegirl.icu/MediaWiki:Gadget-SpecialWikitext.js?_=1}-
萌娘百科界面管理员团队提醒您
大萌字-InterfaceAdmin.png
本页面由萌娘百科界面管理员团队在其 GitHub 库内进行维护,通过机器人自动生成可被 MediaWiki Gadget 扩展接受的版本并保存到此处。
Co-authored-by: Bhsd <55071315+bhsd-harry📧users.noreply.github.com>↩Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com>
如果您有任何意见或建议,建议您到技术实现版提出。
function (input_str, new_str, _escape) {
/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/SpecialWikitext/MediaWiki:Gadget-SpecialWikitext.js|user=[[U:AnnAngela]]|co-authors=[[U:Bhsd]]、GH:github-actions[bot]|longId=bf83eaea8eb4d94405bdf6885ec072fec997dd56|shortId=bf83eaea|summary=ci: use eslint flat config (#400)|body=<nowiki>Co-authored-by: Bhsd <55071315+bhsd-harry📧users.noreply.github.com>↩Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}'; 

/* <pre> */

"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 __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.");
};
(function () { return __awaiter(void 0, void 0, void 0, function () {
    var getCleanText, wikiTextKey, lua_addText, lua_getString, lua_getContentText, lua_getObjText, lua_getCSSwikitext, lua_getJSwikitext, lua_getJSONwikitext, lua_check, api, wgPageName, wgRevisionId, wgUserName, noticeHTML, mwConfigIfMatchInLowerCase, getLanguage, loadingFailNotice, removeLoadingNotice, addParsedWikitext, addLoadingNotice, ifNeedPreview, mwAddWikiText, mwAddLuaText, mwGetFromNowRevision, mwApplyNotice;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0:
                if (mw.config.get("wgIsSpecialWikitextPreview")) {
                    return [2];
                }
                mw.config.set("wgIsSpecialWikitextPreview", true);
                return [4, $.ready];
            case 1:
                _a.sent();
                getCleanText = function (input) { return typeof input === "string" || input ? "".concat(input).trim() : ""; };
                wikiTextKey = "_addText";
                lua_addText = function (input_str, new_str, _escape) {
                    var input_string = input_str;
                    if (new_str !== "") {
                        if (input_string !== "") {
                            input_string += "\n";
                        }
                        var text = new_str;
                        if (_escape) {
                            var escape_str = JSON.parse("[".concat(JSON.stringify("".concat(new_str).replace(/\\([ux])/ig, "$1")).replace(/\\\\/g, "\\"), "]"))[0];
                            text = escape_str;
                        }
                        input_string += text;
                    }
                    return input_string;
                };
                lua_getString = function (str) {
                    var test_str = /[^\n]*\*\//.exec(str);
                    if (test_str) {
                        test_str = test_str[0] || "";
                        test_str = test_str.substr(0, test_str.length - 2);
                    }
                    else {
                        test_str = str;
                    }
                    var trim_check = getCleanText(test_str);
                    var first_char = trim_check.charAt(0);
                    if (first_char === trim_check.charAt(trim_check.length - 1) && (first_char === "'" || first_char === '"')) {
                        return trim_check.substr(1, trim_check.length - 2);
                    }
                    return test_str;
                };
                lua_getContentText = function (str) {
                    var wikitext = "";
                    try {
                        str.replace(new RegExp("".concat(wikiTextKey, "\\s*\\{[^c\\}]*content\\s*:\\s*[^\n]*"), "g"), function (text) {
                            var temp_text = (/content\s*:\s*[^\n]*/.exec(text) || ["content:"])[0]
                                .replace(/^[\s\uFEFF\xA0\t\r\n\f ;}]+|[\s\uFEFF\xA0\t\r\n\f ;}]+$/g, "")
                                .replace(/\s*content\s*:\s*/, "");
                            if (wikitext !== "") {
                                wikitext += "\n";
                            }
                            wikitext += lua_getString(temp_text);
                            return text;
                        });
                    }
                    catch (_a) {
                        return "";
                    }
                    return wikitext;
                };
                lua_getObjText = function (str) {
                    var wikitext = "";
                    try {
                        str.replace(new RegExp("".concat(wikiTextKey, "\\s*[\\=:]\\s*[^\n]*"), "g"), function (text) {
                            var temp_text = text.replace(/^[\s\uFEFF\xA0\t\r\n\f ;}]+|[\s\uFEFF\xA0\t\r\n\f ;}]+$/g, "")
                                .replace(new RegExp("".concat(wikiTextKey, "\\s*[\\=:]\\s*")), "");
                            if (wikitext !== "") {
                                wikitext += "\n";
                            }
                            wikitext += lua_getString(temp_text);
                            return text;
                        });
                    }
                    catch (_a) {
                        return "";
                    }
                    return wikitext;
                };
                lua_getCSSwikitext = function (input_string) {
                    var wikitext = "";
                    var css_text = getCleanText(input_string || $("#wpTextbox1").val() || "");
                    if (css_text === "") {
                        return "";
                    }
                    wikitext = lua_addText(wikitext, lua_getContentText(css_text), true);
                    wikitext = lua_addText(wikitext, lua_getObjText(css_text), true);
                    return wikitext;
                };
                lua_getJSwikitext = function (input_string) {
                    var wikitext = "";
                    var js_text = getCleanText(input_string || $("#wpTextbox1").val() || "");
                    if (js_text === "") {
                        return "";
                    }
                    wikitext = lua_addText(wikitext, lua_getObjText(js_text), true);
                    return wikitext;
                };
                lua_getJSONwikitext = function (input_string) {
                    var wikitext = "";
                    var json_text = getCleanText(input_string || $("#wpTextbox1").val() || "");
                    if (json_text === "") {
                        return "";
                    }
                    try {
                        var json_data_1 = JSON.parse(json_text);
                        Object.keys(json_data_1).forEach(function (key) {
                            var k = key, v = json_data_1[key];
                            if (new RegExp(wikiTextKey).exec(k) && typeof v === "string") {
                                wikitext = lua_addText(wikitext, v);
                            }
                            if (typeof v !== "string") {
                                for (var prop in v) {
                                    if (Object.hasOwnProperty.bind(v)(prop)) {
                                        var testArr_k = prop, testArr_v = v[prop];
                                        if (new RegExp(wikiTextKey).exec(testArr_k) && typeof testArr_v === "string") {
                                            wikitext = lua_addText(wikitext, testArr_v);
                                        }
                                    }
                                }
                            }
                        });
                    }
                    catch (_a) {
                        return "";
                    }
                    return wikitext;
                };
                lua_check = function (input_string, content_model) {
                    var contentModel = "".concat(content_model || mw.config.get("wgPageContentModel")).toLowerCase();
                    switch (contentModel) {
                        case "json":
                            return lua_getJSONwikitext(input_string);
                        case "js":
                        case "javascript":
                        case "text":
                        case "wiki":
                            return lua_getJSwikitext(input_string);
                        case "css":
                        case "sanitized-css":
                            return lua_getCSSwikitext(input_string);
                        default:
                            return "";
                    }
                };
                api = new mw.Api();
                wgPageName = mw.config.get("wgPageName");
                wgRevisionId = mw.config.get("wgRevisionId");
                wgUserName = mw.config.get("wgUserName");
                noticeHTML = {
                    loading: "<div class=\"mw-_addText-preview-loading\"><div class=\"quotebox\" style=\"margin: auto; width: 50%; padding: 6px; border: 1px solid #aaa; font-size: 88%; background-color: #F9F9F9;\"><div class=\"mw-_addText-preview-loading-content\" style=\"background-color: #F9F9F9; color: black; text-align: center; font-size: larger;\"><img src=\"https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif\" decoding=\"async\" data-file-width=\"64\" data-file-height=\"64\" style=\"width: 32px; height: 32px;\"> ".concat(wgULS("预览加载中...", "預覽載入中..."), " </div></div></div>"),
                    fail: "<img src=\"https://img.moegirl.org.cn/common/5/5f/Ambox_warning_orange.svg\" decoding=\"async\" data-file-width=\"48\" data-file-height=\"48\" width=\"32\" height=\"32\">".concat(wgULS("预览加载失败", "預覽載入失敗"))
                };
                mwConfigIfMatchInLowerCase = function (key, preferValues) {
                    var data = getCleanText(mw.config.get(key)).toLowerCase();
                    if (!data) {
                        return false;
                    }
                    return (Array.isArray(preferValues) ? preferValues : preferValues ? [preferValues] : []).includes(data);
                };
                getLanguage = function () {
                    var lang = mw.config.get("wgUserLanguage");
                    if (lang.includes("zh")) {
                        return mw.config.get("wgUserVariant");
                    }
                    return lang;
                };
                loadingFailNotice = function () { return $(".mw-_addText-preview-loading-content").html(noticeHTML.fail); };
                removeLoadingNotice = function () { return $(".mw-_addText-preview-loading").empty(); };
                addParsedWikitext = function (html) {
                    var e_1, _a;
                    var previewLoading = $(".mw-_addText-preview-loading");
                    if (previewLoading.length > 0) {
                        previewLoading.html(html);
                        return;
                    }
                    var node = $(html);
                    try {
                        for (var _b = __values([".diff-currentversion-title", ".previewnote", ".mw-undelete-revision", "#mw-content-text"]), _c = _b.next(); !_c.done; _c = _b.next()) {
                            var selector = _c.value;
                            var anchor = $(selector);
                            if (anchor.length > 0) {
                                anchor.after(node);
                                return;
                            }
                        }
                    }
                    catch (e_1_1) { e_1 = { error: e_1_1 }; }
                    finally {
                        try {
                            if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
                        }
                        finally { if (e_1) throw e_1.error; }
                    }
                };
                addLoadingNotice = function () { return addParsedWikitext(noticeHTML.loading); };
                ifNeedPreview = function () { return document.body.innerHTML.includes("_addText"); };
                mwAddWikiText = function (wikitext, pagename, isPreview) { return __awaiter(void 0, void 0, void 0, function () {
                    var text, params, data, parsedWikitext, parsedHTML, e_2;
                    var _a, _b;
                    return __generator(this, function (_c) {
                        switch (_c.label) {
                            case 0:
                                text = getCleanText(wikitext);
                                if (text.length === 0) {
                                    removeLoadingNotice();
                                    return [2];
                                }
                                params = {
                                    action: "parse",
                                    assertuser: wgUserName,
                                    uselang: getLanguage(),
                                    useskin: mw.config.get("skin"),
                                    title: pagename,
                                    text: text,
                                    contentmodel: "wikitext",
                                    prop: "text",
                                    format: "json"
                                };
                                if (isPreview) {
                                    params.preview = true;
                                    params.disableeditsection = true;
                                }
                                _c.label = 1;
                            case 1:
                                _c.trys.push([1, 3, , 4]);
                                return [4, api.post(params)];
                            case 2:
                                data = _c.sent();
                                parsedWikitext = (_b = (_a = data === null || data === void 0 ? void 0 : data.parse) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b["*"];
                                if (!parsedWikitext) {
                                    return [2];
                                }
                                parsedHTML = getCleanText(parsedWikitext);
                                if (parsedHTML !== "") {
                                    addParsedWikitext(parsedHTML);
                                }
                                else {
                                    removeLoadingNotice();
                                }
                                return [3, 4];
                            case 3:
                                e_2 = _c.sent();
                                console.error(e_2);
                                loadingFailNotice();
                                return [3, 4];
                            case 4: return [2];
                        }
                    });
                }); };
                mwAddLuaText = function (wikitext, isPreview, callback) { return __awaiter(void 0, void 0, void 0, function () {
                    var temp_module_name, module_call, text, params, data, parsedWikitext, parsedHTML, e_3;
                    var _a, _b;
                    return __generator(this, function (_c) {
                        switch (_c.label) {
                            case 0:
                                temp_module_name = "AddText/Temp/Module/Data.lua";
                                module_call = {
                                    wikitext: "#invoke:",
                                    pagename: "Module:"
                                };
                                text = getCleanText(wikitext);
                                if (text.length === 0) {
                                    removeLoadingNotice();
                                    return [2];
                                }
                                params = {
                                    action: "parse",
                                    assertuser: wgUserName,
                                    uselang: getLanguage(),
                                    useskin: mw.config.get("skin"),
                                    format: "json",
                                    title: wgPageName,
                                    text: "{{".concat(module_call.wikitext).concat(temp_module_name, "|main}}"),
                                    prop: "text",
                                    contentmodel: "wikitext",
                                    templatesandboxtitle: module_call.pagename + temp_module_name,
                                    templatesandboxtext: "return {main=function()\nxpcall(function()\n".concat(wikitext, "\nend,function()end)\nlocal moduleWikitext = package.loaded[\"Module:ModuleWikitext\"]\nif moduleWikitext then\nlocal wikitext = moduleWikitext.main()\nif mw.text.trim(wikitext)~=''then\nreturn mw.getCurrentFrame():preprocess(moduleWikitext.main())\nend\nend\nreturn ''\nend}"),
                                    templatesandboxcontentmodel: "Scribunto",
                                    templatesandboxcontentformat: "text/plain"
                                };
                                if (isPreview) {
                                    params.preview = true;
                                    params.disableeditsection = true;
                                }
                                _c.label = 1;
                            case 1:
                                _c.trys.push([1, 3, , 4]);
                                return [4, api.post(params)];
                            case 2:
                                data = _c.sent();
                                parsedWikitext = (_b = (_a = data === null || data === void 0 ? void 0 : data.parse) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b["*"];
                                if (!parsedWikitext) {
                                    return [2];
                                }
                                parsedHTML = getCleanText(parsedWikitext);
                                if (parsedHTML !== "") {
                                    if (!$(parsedHTML).find(".scribunto-error").text().includes(temp_module_name)) {
                                        if (typeof callback === "function") {
                                            callback(parsedHTML);
                                        }
                                        else {
                                            addParsedWikitext(parsedHTML);
                                        }
                                    }
                                    else {
                                        removeLoadingNotice();
                                    }
                                }
                                else {
                                    removeLoadingNotice();
                                }
                                return [3, 4];
                            case 3:
                                e_3 = _c.sent();
                                console.error(e_3);
                                loadingFailNotice();
                                return [3, 4];
                            case 4: return [2];
                        }
                    });
                }); };
                mwGetFromNowRevision = function () { return __awaiter(void 0, void 0, void 0, function () {
                    var data, parsedWikitext, parsedHTML, pageContent, e_4;
                    var _a, _b;
                    return __generator(this, function (_c) {
                        switch (_c.label) {
                            case 0:
                                _c.trys.push([0, 2, , 3]);
                                return [4, api.post({
                                        action: "parse",
                                        assertuser: wgUserName,
                                        oldid: wgRevisionId,
                                        prop: "wikitext"
                                    })];
                            case 1:
                                data = _c.sent();
                                parsedWikitext = (_b = (_a = data === null || data === void 0 ? void 0 : data.parse) === null || _a === void 0 ? void 0 : _a.wikitext) === null || _b === void 0 ? void 0 : _b["*"];
                                if (!parsedWikitext) {
                                    return [2];
                                }
                                parsedHTML = lua_check(getCleanText(parsedWikitext));
                                pageContent = getCleanText("".concat(document.querySelector("#mw-clearyourcache") ? "{{#invoke:SpecialWikitext/Template|int|clearyourcache}}" : "").concat(parsedHTML));
                                if (pageContent) {
                                    mwAddWikiText(pageContent, wgPageName, true);
                                }
                                else {
                                    removeLoadingNotice();
                                }
                                return [3, 3];
                            case 2:
                                e_4 = _c.sent();
                                console.error(e_4);
                                removeLoadingNotice();
                                return [3, 3];
                            case 3: return [2];
                        }
                    });
                }); };
                mwApplyNotice = function (pagename, subPagename) { return __awaiter(void 0, void 0, void 0, function () {
                    var data, parsedWikitext, parsedHTML, e_5;
                    var _a, _b;
                    return __generator(this, function (_c) {
                        switch (_c.label) {
                            case 0:
                                _c.trys.push([0, 2, , 3]);
                                return [4, api.post({
                                        action: "parse",
                                        assertuser: wgUserName,
                                        uselang: getLanguage(),
                                        useskin: mw.config.get("skin"),
                                        title: "".concat(pagename).concat(subPagename),
                                        text: "".concat("{{#invoke:SpecialWikitext/Template|getNotices|").concat(pagename, "|").concat(subPagename, "}}"),
                                        prop: "text",
                                        format: "json"
                                    })];
                            case 1:
                                data = _c.sent();
                                parsedWikitext = (_b = (_a = data === null || data === void 0 ? void 0 : data.parse) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b["*"];
                                if (!parsedWikitext) {
                                    return [2];
                                }
                                parsedHTML = getCleanText(parsedWikitext);
                                if (getCleanText($(parsedHTML).text())) {
                                    addParsedWikitext(parsedHTML);
                                }
                                return [3, 3];
                            case 2:
                                e_5 = _c.sent();
                                console.error(e_5);
                                return [3, 3];
                            case 3: return [2];
                        }
                    });
                }); };
                (function () {
                    if (mwConfigIfMatchInLowerCase("wgPageContentModel", ["javascript", "js", "json", "text", "css", "sanitized-css"])) {
                        if (document.querySelector(".previewnote")) {
                            var previewNode = $(".previewnote .mw-message-box-warning > p > b a");
                            if (previewNode.length > 0) {
                                var path = decodeURI(previewNode.attr("href")).replace(/^\//, "");
                                if (path !== wgPageName) {
                                    return;
                                }
                            }
                            var addWikitext = "".concat(lua_check());
                            if (addWikitext) {
                                addLoadingNotice();
                                mwAddWikiText(addWikitext, wgPageName, true);
                            }
                        }
                        else if (!document.querySelector(".mw-_addText-content") && mwConfigIfMatchInLowerCase("wgAction", "view")) {
                            if (!ifNeedPreview()) {
                                return;
                            }
                            $("#mw-clearyourcache").empty();
                            if (!document.querySelector("#wpTextbox1")) {
                                addLoadingNotice();
                                mwGetFromNowRevision();
                            }
                        }
                        else if (document.querySelector("#mw-revision-info") && mwConfigIfMatchInLowerCase("wgAction", "view")) {
                            if (!document.querySelector("#wpTextbox1")) {
                                $("#mw-clearyourcache").html(noticeHTML.loading);
                                mwGetFromNowRevision();
                            }
                        }
                        else {
                            removeLoadingNotice();
                        }
                    }
                    else if (mwConfigIfMatchInLowerCase("wgPageContentModel", ["scribunto", "lua"])) {
                        if (!ifNeedPreview()) {
                            return;
                        }
                        if (document.querySelector("#wpTextbox1") && document.querySelector("table.diff") && !document.querySelector(".previewnote") && !mwConfigIfMatchInLowerCase("wgAction", "view")) {
                            $("#wikiDiff").after(noticeHTML.loading);
                            mwAddLuaText($("#wpTextbox1").val(), true);
                        }
                    }
                    else if (document.querySelector(".mw-undelete-revision")) {
                        if (!ifNeedPreview()) {
                            return;
                        }
                        if (document.querySelector(".specialWikitextJSON, pre, .mw-json")) {
                            var $tryGetWiki = $("textarea").val();
                            var tryAddWiki = getCleanText(lua_getJSONwikitext($tryGetWiki)) || getCleanText(lua_getCSSwikitext($tryGetWiki));
                            if (tryAddWiki) {
                                addLoadingNotice();
                                mwAddWikiText(tryAddWiki, mw.config.get("wgRelevantPageName"), true);
                            }
                            else if (/Module[_ ]wikitext.*_addText/i.exec($(".mw-parser-output").text())) {
                            }
                        }
                    }
                    else if (!document.querySelector(".mw-editnotice") && mwConfigIfMatchInLowerCase("wgCanonicalNamespace", "special")) {
                        var fullPagename = getCleanText(mw.config.get("wgCanonicalSpecialPageName"));
                        var subPagename = fullPagename.replace(RegExp("^".concat(mw.config.get("wgCanonicalNamespace"), ":[^/]+")), "");
                        if (fullPagename) {
                            var fullpagename = "".concat(mw.config.get("wgCanonicalNamespace"), ":").concat(fullPagename);
                            mwApplyNotice(fullpagename, subPagename);
                        }
                    }
                    else {
                        removeLoadingNotice();
                    }
                })();
                (function () { return __awaiter(void 0, void 0, void 0, function () {
                    var testcaseList, wikitextPackages, _loop_1, testcaseList_1, testcaseList_1_1, testcaseNode, wikitextPackage, wikitext, params, data, parsedWikitext, parsedHTML, parsedNodes, i, e_6;
                    var e_7, _a;
                    var _b, _c;
                    return __generator(this, function (_d) {
                        switch (_d.label) {
                            case 0:
                                if (!ifNeedPreview()) {
                                    return [2];
                                }
                                testcaseList = document.querySelectorAll(".special-wikitext-preview-testcase");
                                if (testcaseList.length <= 0) {
                                    return [2];
                                }
                                wikitextPackages = [];
                                _loop_1 = function (testcaseNode) {
                                    var codeNode = testcaseNode.querySelector(".specialWikitextJSON, pre, .mw-json");
                                    if (!codeNode) {
                                        return "continue";
                                    }
                                    var lang = getCleanText(codeNode.getAttribute("lang")).toLowerCase();
                                    var code = getCleanText(codeNode.innerText);
                                    if (!code) {
                                        return "continue";
                                    }
                                    if (["javascript", "js", "css", "json", "wiki", "text"].includes(lang)) {
                                        var addWikitext = getCleanText(lua_check(code, lang));
                                        if (addWikitext) {
                                            var i = "".concat(wikitextPackages.length);
                                            $(testcaseNode).attr("data-preview-id", i).prepend(noticeHTML.loading);
                                            wikitextPackages.push("<div class=\"special-wikitext-preview-testcase\" data-preview-id=\"".concat(i, "\">\n").concat(addWikitext, "\n</div>"));
                                        }
                                    }
                                    else if (["lua", "scribunto"].includes(lang)) {
                                        mwAddLuaText(code, true, function (wikitext) { return $(testcaseNode).prepend(wikitext); });
                                    }
                                };
                                try {
                                    for (testcaseList_1 = __values(testcaseList), testcaseList_1_1 = testcaseList_1.next(); !testcaseList_1_1.done; testcaseList_1_1 = testcaseList_1.next()) {
                                        testcaseNode = testcaseList_1_1.value;
                                        _loop_1(testcaseNode);
                                    }
                                }
                                catch (e_7_1) { e_7 = { error: e_7_1 }; }
                                finally {
                                    try {
                                        if (testcaseList_1_1 && !testcaseList_1_1.done && (_a = testcaseList_1["return"])) _a.call(testcaseList_1);
                                    }
                                    finally { if (e_7) throw e_7.error; }
                                }
                                wikitextPackage = getCleanText(wikitextPackages.join(""));
                                if (!wikitextPackage) {
                                    return [2];
                                }
                                wikitext = "<div class=\"special-wikitext-preview-testcase-container\">".concat(wikitextPackage, "</div>");
                                params = {
                                    action: "parse",
                                    assertuser: wgUserName,
                                    text: wikitext,
                                    contentmodel: "wikitext",
                                    prop: "text",
                                    format: "json",
                                    preview: true,
                                    disableeditsection: true
                                };
                                _d.label = 1;
                            case 1:
                                _d.trys.push([1, 3, , 4]);
                                return [4, api.post(params)];
                            case 2:
                                data = _d.sent();
                                parsedWikitext = (_c = (_b = data === null || data === void 0 ? void 0 : data.parse) === null || _b === void 0 ? void 0 : _b.text) === null || _c === void 0 ? void 0 : _c["*"];
                                if (!parsedWikitext) {
                                    return [2];
                                }
                                parsedHTML = getCleanText(parsedWikitext);
                                if (!parsedHTML) {
                                    return [2];
                                }
                                parsedNodes = $(parsedHTML);
                                for (i = 0; i <= wikitextPackages.length; i++) {
                                    $(".special-wikitext-preview-testcase[data-preview-id=".concat(i, "]")).find(".mw-_addText-preview-loading").before(parsedNodes.find(".special-wikitext-preview-testcase-container > .special-wikitext-preview-testcase[data-preview-id=".concat(i, "]")));
                                }
                                removeLoadingNotice();
                                return [3, 4];
                            case 3:
                                e_6 = _d.sent();
                                console.error(e_6);
                                return [3, 4];
                            case 4: return [2];
                        }
                    });
                }); })();
                return [2];
        }
    });
}); })(); 

/* </pre> */