你现在正在访问的是萌娘百科用于保存和管理图片、音频等媒体文件的子项目萌娘共享,想要回到萌娘百科,请使用浏览器上的返回按钮、或点击这里
MediaWiki:Gadget-queryContributions.js
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
/** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/queryContributions/MediaWiki:Gadget-queryContributions.js|user=[[U:AnnAngela]]|co-authors=|longId=64c79afacaa4df8dc6a6ca053482f2a58f9ec684|shortId=64c79afa|summary=feat: Update to echarts📧5.5.1}}'; /* <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 __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 __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 (function () { return __awaiter(void 0, void 0, void 0, function () { var target, userRights, hasApiHighLimits, isPatrolViewable, wgUserName, upperFirstCase, api, ns, p; return __generator(this, function (_a) { switch (_a.label) { case 0: if (mw.config.get("wgCanonicalSpecialPageName") !== "Contributions") { return [2]; } target = (document.querySelector('[name="target"]') || {}).value; if (typeof target !== "string" || target.length === 0) { return [2]; } return [4, mw.user.getRights()]; case 1: userRights = _a.sent(); hasApiHighLimits = !userRights.includes("apihighlimits"); isPatrolViewable = userRights.includes("patrol") || userRights.includes("patrolmarks"); wgUserName = mw.config.get("wgUserName"); upperFirstCase = function (s) { return /^[a-z]/.test(s) ? s.substring(0, 1).toUpperCase() + s.substring(1) : s; }; api = new mw.Api(); ns = { 0: "", 1: "讨论", 2: "用户", 3: "用户讨论", 4: "萌娘百科", 5: "萌娘百科讨论", 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" }; p = $('<form style="max-width:100%;overflow-x:auto"><fieldset><legend style="position:sticky;left:.5em">用户贡献分布</legend><p id="queryContributions">是否需要加载用户贡献分布(对编辑数量较多的用户慎重使用!)<button id="confirmQueryContributions">确认</button> <button id="cancelQueryContributions">取消</button></p></fieldset></form>').insertAfter("#mw-content-text > form").find("#queryContributions"); p.find("#confirmQueryContributions").on("click", function () { return __awaiter(void 0, void 0, void 0, function () { var list, nslist, globalInfo, GHIAEditCount, _a, _b, content, GHIAHistory, table, chartData, GHIAInfo, fieldset; return __generator(this, function (_c) { switch (_c.label) { case 0: p.text("\u52A0\u8F7D\u4E2D".concat(hasApiHighLimits ? "(由于您没有“在API查询中使用更高的上限”[apihighlimits]权限,本次加载将需要较长时间,请稍等)" : "", "\u2026\u2026")); return [4, (function () { return __awaiter(void 0, void 0, void 0, function () { var result, eol, uccontinue, _result; return __generator(this, function (_a) { switch (_a.label) { case 0: result = []; eol = Symbol(); uccontinue = undefined; _a.label = 1; case 1: if (!(uccontinue !== eol)) return [3, 3]; return [4, api.post({ action: "query", assertuser: wgUserName, format: "json", list: "usercontribs", ucuser: target, ucprop: "title|flags".concat(isPatrolViewable ? "|patrolled" : ""), uccontinue: uccontinue, uclimit: "max" })]; case 2: _result = _a.sent(); if (_result["continue"]) { uccontinue = _result["continue"].uccontinue; p[0].innerText += "…"; } else { uccontinue = eol; } result.push.apply(result, __spreadArray([], __read(_result.query.usercontribs), false)); return [3, 1]; case 3: return [2, result]; } }); }); })()]; case 1: list = _c.sent(); nslist = Object.fromEntries(Object.keys(ns).map(function (key) { return [key, { count: 0, patrolled: 0, autopatrolled: 0, "new": 0, distinct: new Set() }]; })); globalInfo = { patrolled: 0, autopatrolled: 0, "new": 0, distinct: new Set() }; list.forEach(function (item) { nslist[item.ns].count++; if (Reflect.has(item, "patrolled")) { nslist[item.ns].patrolled++; globalInfo.patrolled++; } if (Reflect.has(item, "autopatrolled")) { nslist[item.ns].autopatrolled++; globalInfo.autopatrolled++; } if (Reflect.has(item, "new")) { nslist[item.ns]["new"]++; globalInfo["new"]++; } nslist[item.ns].distinct.add(item.title); globalInfo.distinct.add(item.title); }); GHIAEditCount = 0; if (!["zh.moegirl.org.cn", "mzh.moegirl.org.cn"].includes(mw.config.get("wgServerName"))) return [3, 3]; return [4, api.post({ action: "query", assertuser: wgUserName, titles: "MediaWiki:GHIAHistory.json", prop: "revisions", rvprop: ["content"], rvlimit: 1, rvdir: "older", formatversion: 2 })]; case 2: _a = __read.apply(void 0, [(_c.sent()).query.pages, 1]), _b = __read(_a[0].revisions, 1), content = _b[0].content; GHIAHistory = JSON.parse(content); GHIAEditCount = Reflect.has(GHIAHistory, "U:".concat(target)) ? GHIAHistory["U:".concat(target)].reduce(function (p, _a) { var changedFiles = _a.changedFiles; return p + changedFiles; }, 0) : 0; nslist[8].count += GHIAEditCount; _c.label = 3; case 3: table = $("<table class=\"wikitable sortable\"><thead><tr><th>\u540D\u5B57\u7A7A\u95F4</th><th>\u7F16\u8F91\u6B21\u6570</th>".concat(isPatrolViewable ? "<th>被巡查次数</th><th>被手动巡查次数</th>" : "", "<th>\u4E0D\u540C\u9875\u9762\u6570\u91CF</th>><th>\u521B\u5EFA\u9875\u9762\u6570\u91CF</th></tr></thead><tbody></tbody></table>")).find("tbody"); p.html("\u8BE5\u7528\u6237\u5728\u672C\u7AD9\u672A\u88AB\u5220\u9664\u7684\u7F16\u8F91\u5171\u6709 ".concat(list.length, " \u6B21").concat(isPatrolViewable ? "\uFF08\u5176\u4E2D\u6709 ".concat(globalInfo.patrolled, " \u6B21\u7F16\u8F91\u88AB\u5DE1\u67E5\uFF0C").concat(globalInfo.patrolled - globalInfo.autopatrolled, " \u6B21\u7F16\u8F91\u88AB\u624B\u52A8\u5DE1\u67E5<sup style=\"color: blue;\">[\u6CE8\uFF1A\u901A\u8FC7api\u7F16\u8F91\u4E0D\u4F1A\u81EA\u52A8\u5DE1\u67E5]</sup>\uFF09") : "", "\uFF0C\u5171\u7F16\u8F91 ").concat(globalInfo.distinct.size, " \u4E2A\u4E0D\u540C\u9875\u9762\uFF0C\u521B\u5EFA\u4E86 ").concat(globalInfo["new"], " \u4E2A\u9875\u9762\u3002\u6309\u540D\u5B57\u7A7A\u95F4\u5212\u5206\u5982\u4E0B\uFF1A")); chartData = []; Object.entries(nslist).filter(function (_a) { var _b = __read(_a, 2), count = _b[1].count; return count > 0; }).sort(function (_a, _b) { var _c = __read(_a, 1), a = _c[0]; var _d = __read(_b, 1), b = _d[0]; return a - b; }).forEach(function (_a) { var _b = __read(_a, 2), nsnumber = _b[0], _c = _b[1], count = _c.count, patrolled = _c.patrolled, autopatrolled = _c.autopatrolled, distinct = _c.distinct, newCount = _c["new"]; table.append("<tr><td data-sort-value=\"".concat(nsnumber, "\">").concat(+nsnumber === 0 ? "(主名字空间)" : upperFirstCase(ns[+nsnumber]), "</td><td>").concat(count, "</td>").concat(isPatrolViewable ? "<td>".concat(patrolled, "</td><td>").concat(patrolled - autopatrolled, "</td>") : "", "<td>").concat(distinct.size, "</td><td>").concat(newCount, "</td></tr>")); chartData.push({ value: count, name: +nsnumber === 0 ? "(主)" : upperFirstCase(ns[+nsnumber]) }); }); table.closest("table").insertAfter(p).tablesorter(); if (GHIAEditCount > 0) { GHIAInfo = $("<p>"); GHIAInfo.text("\u6CE8\uFF1A\u6765\u81EA GHIA \u5E93\u7684\u672A\u88AB\u5220\u9664\u7684\u7F16\u8F91\u5171\u6709 ".concat(GHIAEditCount, " \u7B14\uFF0C\u8FD9\u4E9B\u7F16\u8F91\u5747\u4F1A\u88AB\u89C6\u4E3A MediaWiki \u540D\u5B57\u7A7A\u95F4\u4E0B\u7684\u7F16\u8F91\uFF0C\u4E14\u4E0D\u4F1A\u88AB\u7EDF\u8BA1\u4E3A\u201C\u88AB\u5DE1\u67E5\u201D\u201C\u88AB\u624B\u52A8\u5DE1\u67E5\u201D\u201C\u4E0D\u540C\u9875\u9762\u201D\u548C\u201C\u521B\u5EFA\u9875\u9762\u201D\u3002\u5728 GHIA \u5E93\u91CC\u5BF9\u5DF2\u88AB\u5220\u9664\u6587\u4EF6\u7684\u7F16\u8F91\u65E0\u6CD5\u7EDF\u8BA1\u3002")); table.closest("table").after(GHIAInfo); } fieldset = p.closest("fieldset"); fieldset.append('<button id="toChartQueryContributions">显示饼图</button>'); fieldset.find("#toChartQueryContributions").on("click", function (e) { return __awaiter(void 0, void 0, void 0, function () { var chart; return __generator(this, function (_a) { switch (_a.label) { case 0: $(e.target).remove(); fieldset.append("<div id=\"contributionChart\" style=\"width: 100%; height: 400px;\">加载中……</div>"); return [4, libCachedCode.injectCachedCode("https://npm.elemecdn.com/echarts@5.5.1/dist/echarts.min.js", "script")]; case 1: _a.sent(); chart = echarts.init(document.getElementById("contributionChart")); chart.setOption({ tooltip: { trigger: "item", formatter: "{c} ({d}%)" }, toolbox: { show: true, feature: { saveAsImage: { excludeComponents: ["toolbox"] } } }, legend: { top: "5%", left: "center" }, series: [ { name: "用户贡献分布", type: "pie", radius: ["40%", "70%"], avoidLabelOverlap: false, itemStyle: { borderRadius: 10, borderColor: "#fff", borderWidth: 2 }, label: { show: false, position: "center" }, emphasis: { label: { show: true, fontSize: "40", fontWeight: "bold" } }, labelLine: { show: false }, data: chartData }, ] }); $(window).on("resize", function () { return chart.trigger("resize"); }); return [2]; } }); }); }); return [2]; } }); }); }); p.find("#cancelQueryContributions").on("click", function () { p.closest("fieldset").remove(); }); return [2]; } }); }); })(); }); /* </pre> */