- 欢迎加入官方Discord和Telegram群组!
- 我们正在删除政治内容页面,还您一个干净的H萌娘,净化社区的同时也可以让您认真学习和讨论性知识(?
- 不知道接下来该看什么?可以去查阅本站的优质条目
- 如果您在H萌娘上发现某些内容错误/空缺,请勇于修正/添加!编辑H萌娘其实很容易!(由于遭到破坏,自动确认用户外的编辑现在会先审核 )
- 有任何意见、建议、求助都可以在 讨论版 提出!
User:Irukaza/js/queryContributions.js
跳到导航
跳到搜索
注意:这类代码页面在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- 按住
CTRL+SHIFT+DEL 或 ⌘-Shift-R
来清除缓存! - 或尝试在地址栏的地址最后添加代码
?_=1
来访问最新页面。 - 你还可以在设置中勾选小工具在页面右上角添加清除缓存按钮!
// <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.此工具可以使用自动API查询,显示分名字空间的用户贡献分布",
"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>