“User:Irukaza/common.js”与“User:Irukaza/js/queryContributions.js”:页面之间的差异

H萌娘,万物皆可H的百科全书!
< User:Irukaza(页面间差异)
跳到导航 跳到搜索
imported>=海豚=
无编辑摘要
 
imported>=海豚=
无编辑摘要
 
第1行: 第1行:
 
// <pre>
  if (mw.config.values.wgAction == "view" || mw.config.values.wgAction == "history"){
"use strict";
    document.getElementById("content").innerHTML=window.newtrad2simcore(" "+document.getElementById("bodyContent").innerHTML).substr(1);
$(() => (async () => {
window.origHeadElem.innerHTML=window.newtrad2simcore(" "+window.origHeadElem.innerHTML).substr(1);
   if (mw.config.get("wgCanonicalSpecialPageName") !== "Contributions") {
var convtag=document.getElementById("ca-conv-text");
     return;
convtag.parentElement.innerHTML="<a href=\"javascript:window.simrestorem()\" title=\" 復原\" id=\"ca-conv-text\"> 港台繁體<\/a>";
   }
}
   const target = (document.querySelector('[name="target"]') || {}).value;
   if (typeof target !== "string" || target.length === 0) {
     return;
    }
   await mw.loader.using("mw.Api");
   mw.loader.using("jquery.tablesorter");
   const upperFirstCase = (s) => /^[a-z]/.test(s) ? s.substring(0, 1).toUpperCase() + s.substring(1) : s;
   const api = new mw.Api();
   const p = $('<fieldset><legend>用户贡献分布</legend><p id="queryContributions">分名字空间展现用户贡献分布(编辑数量多的用户需要较长的时间加载)<button id="confirmQueryContributions"> √ 开始加载</button><button id="Description">说明</button></fieldset>').insertAfter("#mw-content-text > form").find("#queryContributions");
   p.find("#Description").on("click", async () => {
         alert([
           "使用说明",
           "1.",
           "2.",
           "3.",
         ].join("\n"));
   });
   p.find("#confirmQueryContributions").on("click", async () => {
     p.text("加载中……");
     const list = await (async () => {
       const result = [];
       const eol = Symbol();
       let uccontinue = undefined;
       while (uccontinue !== eol) {
         const _result = await api.post({
           action: "query",
           format: "json",
           list: "usercontribs",
           ucuser: target,
           ucprop: "title|flags|patrolled",
           uccontinue,
           uclimit: "max",
         });
         if (_result.continue) {
           uccontinue = _result.continue.uccontinue;
           p[0].innerText += " …";
         } else {
           uccontinue = eol;
         }
         result.push(..._result.query.usercontribs);
       }
       return result;
     })();
     const ns = {
       0: "",
       1: "讨论",
       2: "用户",
       3: "用户讨论",
       4: "H萌娘",
       5: "H萌娘讨论",
       6: "文件",
       7: "文件讨论",
       8: "mediawiki",
       9: "mediawiki讨论",
       10: "模板",
       11: "模板讨论",
       12: "帮助",
       13: "帮助讨论",
       14: "分类",
       15: "分类讨论",
       274: "widget",
       275: "widget_talk",
       710: "timedtext",
       711: "timedtext_talk",
       828: "模块",
       829: "模块讨论",
       2300: "gadget",
       2301: "gadget_talk",
       2302: "gadget_definition",
       2303: "gadget_definition_talk",
     };
     const nslist = {
       0: { count: 0, patrolled: 0, autopatrolled: 0 },
       1: { count: 0, patrolled: 0, autopatrolled: 0 },
       2: { count: 0, patrolled: 0, autopatrolled: 0 },
       3: { count: 0, patrolled: 0, autopatrolled: 0 },
       4: { count: 0, patrolled: 0, autopatrolled: 0 },
       5: { count: 0, patrolled: 0, autopatrolled: 0 },
       6: { count: 0, patrolled: 0, autopatrolled: 0 },
       7: { count: 0, patrolled: 0, autopatrolled: 0 },
       8: { count: 0, patrolled: 0, autopatrolled: 0 },
       9: { count: 0, patrolled: 0, autopatrolled: 0 },
       10: { count: 0, patrolled: 0, autopatrolled: 0 },
       11: { count: 0, patrolled: 0, autopatrolled: 0 },
       12: { count: 0, patrolled: 0, autopatrolled: 0 },
       13: { count: 0, patrolled: 0, autopatrolled: 0 },
       14: { count: 0, patrolled: 0, autopatrolled: 0 },
       15: { count: 0, patrolled: 0, autopatrolled: 0 },
       274: { count: 0, patrolled: 0, autopatrolled: 0 },
       275: { count: 0, patrolled: 0, autopatrolled: 0 },
       710: { count: 0, patrolled: 0, autopatrolled: 0 },
       711: { count: 0, patrolled: 0, autopatrolled: 0 },
       828: { count: 0, patrolled: 0, autopatrolled: 0 },
       829: { count: 0, patrolled: 0, autopatrolled: 0 },
       2300: { count: 0, patrolled: 0, autopatrolled: 0 },
       2301: { count: 0, patrolled: 0, autopatrolled: 0 },
       2302: { count: 0, patrolled: 0, autopatrolled: 0 },
       2303: { count: 0, patrolled: 0, autopatrolled: 0 },
     };
     const global = { patrolled: 0, autopatrolled: 0 };
     await mw.loader.using("jquery.tablesorter");
     const table = $('<table class="wikitable sortable"><thead><tr><th>名字空间</th><th>编辑次数</th><th>被巡查次数</th><th>被手动巡查次数</th></tr></thead><tbody></tbody></table>').find("tbody");
     list.forEach((item) => {
       nslist[item.ns].count++;
       if ("patrolled" in item) {
         nslist[item.ns].patrolled++;
         global.patrolled++;
       }
       if ("autopatrolled" in item) {
         nslist[item.ns].autopatrolled++;
         global.autopatrolled++;
       }
     });
     p.html(`该用户在本站未被删除的编辑共有${list.length}次(其中有${global.patrolled}次编辑被巡查,${global.patrolled - global.autopatrolled}次编辑被手动巡查)。按名字空间划分如下:`);
     Object.entries(nslist).filter(([, { count }]) => count > 0).sort(([a], [b]) => a - b).forEach(([nsnumber, { count, patrolled, autopatrolled }]) => table.append(`<tr><td data-sort-value="${nsnumber}">${+nsnumber === 0 ? "(主名字空间)" : upperFirstCase(ns[+nsnumber])}</td><td>${count}</td><td>${patrolled}</td><td>${patrolled - autopatrolled}</td></tr>`));
     table.closest("table").insertAfter(p).tablesorter();
   });
   p.find("#cancelQueryContributions").on("click", () => {
     p.closest("fieldset").remove();
   });
})());
// </pre>

2021年8月12日 (四) 09:58的版本

// <pre>
"use strict";
$(() => (async () => {
    if (mw.config.get("wgCanonicalSpecialPageName") !== "Contributions") {
        return;
    }
    const target = (document.querySelector('[name="target"]') || {}).value;
    if (typeof target !== "string" || target.length === 0) {
        return;
    }
    await mw.loader.using("mw.Api");
    mw.loader.using("jquery.tablesorter");
    const upperFirstCase = (s) => /^[a-z]/.test(s) ? s.substring(0, 1).toUpperCase() + s.substring(1) : s;
    const api = new mw.Api();
    const p = $('<fieldset><legend>用户贡献分布</legend><p id="queryContributions">分名字空间展现用户贡献分布(编辑数量多的用户需要较长的时间加载)<button id="confirmQueryContributions"> √ 开始加载</button><button id="Description">说明</button></fieldset>').insertAfter("#mw-content-text > form").find("#queryContributions");
    p.find("#Description").on("click", async () => {
                alert([
                    "使用说明",
                    "1.",
                    "2.",
                    "3.",
                ].join("\n"));
    });
    p.find("#confirmQueryContributions").on("click", async () => {
        p.text("加载中……");
        const list = await (async () => {
            const result = [];
            const eol = Symbol();
            let uccontinue = undefined;
            while (uccontinue !== eol) {
                const _result = await api.post({
                    action: "query",
                    format: "json",
                    list: "usercontribs",
                    ucuser: target,
                    ucprop: "title|flags|patrolled",
                    uccontinue,
                    uclimit: "max",
                });
                if (_result.continue) {
                    uccontinue = _result.continue.uccontinue;
                    p[0].innerText += "…";
                } else {
                    uccontinue = eol;
                }
                result.push(..._result.query.usercontribs);
            }
            return result;
        })();
        const ns = {
            0: "",
            1: "讨论",
            2: "用户",
            3: "用户讨论",
            4: "H萌娘",
            5: "H萌娘讨论",
            6: "文件",
            7: "文件讨论",
            8: "mediawiki",
            9: "mediawiki讨论",
            10: "模板",
            11: "模板讨论",
            12: "帮助",
            13: "帮助讨论",
            14: "分类",
            15: "分类讨论",
            274: "widget",
            275: "widget_talk",
            710: "timedtext",
            711: "timedtext_talk",
            828: "模块",
            829: "模块讨论",
            2300: "gadget",
            2301: "gadget_talk",
            2302: "gadget_definition",
            2303: "gadget_definition_talk",
        };
        const nslist = {
            0: { count: 0, patrolled: 0, autopatrolled: 0 },
            1: { count: 0, patrolled: 0, autopatrolled: 0 },
            2: { count: 0, patrolled: 0, autopatrolled: 0 },
            3: { count: 0, patrolled: 0, autopatrolled: 0 },
            4: { count: 0, patrolled: 0, autopatrolled: 0 },
            5: { count: 0, patrolled: 0, autopatrolled: 0 },
            6: { count: 0, patrolled: 0, autopatrolled: 0 },
            7: { count: 0, patrolled: 0, autopatrolled: 0 },
            8: { count: 0, patrolled: 0, autopatrolled: 0 },
            9: { count: 0, patrolled: 0, autopatrolled: 0 },
            10: { count: 0, patrolled: 0, autopatrolled: 0 },
            11: { count: 0, patrolled: 0, autopatrolled: 0 },
            12: { count: 0, patrolled: 0, autopatrolled: 0 },
            13: { count: 0, patrolled: 0, autopatrolled: 0 },
            14: { count: 0, patrolled: 0, autopatrolled: 0 },
            15: { count: 0, patrolled: 0, autopatrolled: 0 },
            274: { count: 0, patrolled: 0, autopatrolled: 0 },
            275: { count: 0, patrolled: 0, autopatrolled: 0 },
            710: { count: 0, patrolled: 0, autopatrolled: 0 },
            711: { count: 0, patrolled: 0, autopatrolled: 0 },
            828: { count: 0, patrolled: 0, autopatrolled: 0 },
            829: { count: 0, patrolled: 0, autopatrolled: 0 },
            2300: { count: 0, patrolled: 0, autopatrolled: 0 },
            2301: { count: 0, patrolled: 0, autopatrolled: 0 },
            2302: { count: 0, patrolled: 0, autopatrolled: 0 },
            2303: { count: 0, patrolled: 0, autopatrolled: 0 },
        };
        const global = { patrolled: 0, autopatrolled: 0 };
        await mw.loader.using("jquery.tablesorter");
        const table = $('<table class="wikitable sortable"><thead><tr><th>名字空间</th><th>编辑次数</th><th>被巡查次数</th><th>被手动巡查次数</th></tr></thead><tbody></tbody></table>').find("tbody");
        list.forEach((item) => {
            nslist[item.ns].count++;
            if ("patrolled" in item) {
                nslist[item.ns].patrolled++;
                global.patrolled++;
            }
            if ("autopatrolled" in item) {
                nslist[item.ns].autopatrolled++;
                global.autopatrolled++;
            }
        });
        p.html(`该用户在本站未被删除的编辑共有${list.length}次(其中有${global.patrolled}次编辑被巡查,${global.patrolled - global.autopatrolled}次编辑被手动巡查)。按名字空间划分如下:`);
        Object.entries(nslist).filter(([, { count }]) => count > 0).sort(([a], [b]) => a - b).forEach(([nsnumber, { count, patrolled, autopatrolled }]) => table.append(`<tr><td data-sort-value="${nsnumber}">${+nsnumber === 0 ? "(主名字空间)" : upperFirstCase(ns[+nsnumber])}</td><td>${count}</td><td>${patrolled}</td><td>${patrolled - autopatrolled}</td></tr>`));
        table.closest("table").insertAfter(p).tablesorter();
    });
    p.find("#cancelQueryContributions").on("click", () => {
        p.closest("fieldset").remove();
    });
})());
// </pre>