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