User:Irukaza/js/queryWhatlinkshere.js:修订间差异
imported>=海豚= (创建页面,内容为“// <pre> "use strict"; $(() => (async () => { if (mw.config.get("wgCanonicalSpecialPageName") !== "Whatlinkshere") { return; } const target = (do…”) |
imported>Irukaza 无编辑摘要 |
||
| (未显示2个用户的13个中间版本) | |||
| 第12行: | 第12行: | ||
const upperFirstCase = (s) => /^[a-z]/.test(s) ? s.substring(0, 1).toUpperCase() + s.substring(1) : s; | const upperFirstCase = (s) => /^[a-z]/.test(s) ? s.substring(0, 1).toUpperCase() + s.substring(1) : s; | ||
const api = new mw.Api(); | const api = new mw.Api(); | ||
const p = $('<fieldset><legend>链入情况</legend><p id="queryWhatlinkshere"> | const p = $('<fieldset><legend>链入情况</legend><p id="queryWhatlinkshere">……</p></fieldset>').insertAfter("#mw-content-text > form").find("#queryWhatlinkshere"); | ||
const list = await (async () => { | const list = await (async () => { | ||
const result = []; | const result = []; | ||
| 第32行: | 第32行: | ||
lhcontinue = eol; | lhcontinue = eol; | ||
} | } | ||
result.push(...(Object.values(_result.query.pages)[0].linkshere || [])); | |||
} | } | ||
return result; | return result; | ||
})(); | })(); | ||
const ns = { | const ns = { | ||
0: "", | 0: " 条目", | ||
1: "讨论", | 1: "讨论", | ||
2: "用户", | 2: "用户", | ||
3: "用户讨论", | 3: "用户讨论", | ||
4: "萌娘 | 4: "H 萌娘", | ||
5: "萌娘 | 5: "H 萌娘讨论", | ||
6: "文件", | 6: "文件", | ||
7: "文件讨论", | 7: "文件讨论", | ||
| 第93行: | 第93行: | ||
}; | }; | ||
const global = { redirect: 0 }; | const global = { redirect: 0 }; | ||
p.text(`共有${list.length}个页面含有到本页面的站内链接 | p.text(`共有${list.length}个页面含有到本页面的站内链接,其中有${list.filter((item) => "redirect" in item).length}个重定向页面。`); | ||
if (list.length > 0) { p.append(" 按名字空间划分如下:"); } | |||
const ul = $("<ul/>"); | const ul = $("<ul/>"); | ||
list.forEach((item) => { | list.forEach((item) => { | ||
2022年2月21日 (一) 19:18的最新版本
// <pre>
"use strict";
$(() => (async () => {
if (mw.config.get("wgCanonicalSpecialPageName") !== "Whatlinkshere") {
return;
}
const target = (document.querySelector("#mw-whatlinkshere-target") || {}).value;
if (typeof target !== "string" || target.length === 0) {
return;
}
await mw.loader.using("mw.Api");
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="queryWhatlinkshere">……</p></fieldset>').insertAfter("#mw-content-text > form").find("#queryWhatlinkshere");
const list = await (async () => {
const result = [];
const eol = Symbol();
let lhcontinue = undefined;
while (lhcontinue !== eol) {
const _result = await api.post({
action: "query",
format: "json",
prop: "linkshere",
titles: target,
lhprop: "redirect|title|pageid",
lhcontinue,
lhlimit: "max",
});
if (_result.continue) {
lhcontinue = _result.continue.lhcontinue;
} else {
lhcontinue = eol;
}
result.push(...(Object.values(_result.query.pages)[0].linkshere || []));
}
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, redirect: 0 },
1: { count: 0, redirect: 0 },
2: { count: 0, redirect: 0 },
3: { count: 0, redirect: 0 },
4: { count: 0, redirect: 0 },
5: { count: 0, redirect: 0 },
6: { count: 0, redirect: 0 },
7: { count: 0, redirect: 0 },
8: { count: 0, redirect: 0 },
9: { count: 0, redirect: 0 },
10: { count: 0, redirect: 0 },
11: { count: 0, redirect: 0 },
12: { count: 0, redirect: 0 },
13: { count: 0, redirect: 0 },
14: { count: 0, redirect: 0 },
15: { count: 0, redirect: 0 },
274: { count: 0, redirect: 0 },
275: { count: 0, redirect: 0 },
710: { count: 0, redirect: 0 },
711: { count: 0, redirect: 0 },
828: { count: 0, redirect: 0 },
829: { count: 0, redirect: 0 },
2300: { count: 0, redirect: 0 },
2301: { count: 0, redirect: 0 },
2302: { count: 0, redirect: 0 },
2303: { count: 0, redirect: 0 },
};
const global = { redirect: 0 };
p.text(`共有${list.length}个页面含有到本页面的站内链接,其中有${list.filter((item) => "redirect" in item).length}个重定向页面。`);
if (list.length > 0) { p.append("按名字空间划分如下:"); }
const ul = $("<ul/>");
list.forEach((item) => {
nslist[item.ns].count++;
if ("redirect" in item) {
nslist[item.ns].redirect++;
global.redirect++;
}
});
Object.entries(nslist).filter(([, { count }]) => count > 0).sort(([a], [b]) => a - b).forEach(([nsnumber, { count, redirect }]) => ul.append(`<li>${nsnumber === 0 ? "(主名字空间)" : upperFirstCase(ns[nsnumber])}:${count}个页面(其中有${redirect}个重定向页面)`));
p.after(ul);
})());
// </pre>