MediaWiki:Gadget-Navbox-link.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),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
// <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 (_) 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 };
}
};
$(function () {
if (mw.config.get("wgNamespaceNumber") !== 10 || $("#mw-content-text .navbox:not(.template-documentation .navbox)").length === 0) {
return;
}
var pageNonExist = wgULS("(页面不存在)", "(頁面不存在)");
var wgPageName = mw.config.get("wgPageName");
var api = new mw.Api();
var targetLoc = $("<div>", {
id: "not-listed-articles"
}).hide();
var refresh = $("<a>", {
href: "javascript:void(0)",
title: wgULS("强制刷新", "強制重新整理"),
id: "not-listed-articles-refresh",
text: wgULS("未添加本模版的条目(点击刷新)", "未新增本模版的條目(點選重新整理)", null, null, "未新增本模版的條目(點擊重新整理)")
});
targetLoc.append("<hr>");
$("#catlinks").append(targetLoc);
var targetUl = $("<ul>", {
id: "not-listed-articles-list"
});
targetLoc.append(refresh).append(":").append(targetUl);
var generateSelector = function (_title, redirects) {
var title = _title.replace(/"/g, '\\"');
var selector = "a[title=\"".concat(title, "\"], a[title=\"").concat(title).concat(pageNonExist, "\"], a[data-title=\"").concat(title, "\"], a[data-title=\"").concat(title).concat(pageNonExist, "\"]");
if (typeof redirects[title] === "string") {
selector += ", a[title=\"".concat(redirects[title], "\"], a[title=\"").concat(redirects[title]).concat(pageNonExist, "\"], a[data-title=\"").concat(redirects[title], "\"], a[data-title=\"").concat(redirects[title]).concat(pageNonExist, "\"]");
}
return selector;
};
refresh.on("click", function (e) { return __awaiter(void 0, void 0, void 0, function () {
var result, redirects_1, _loop_1, _i, _a, _b, templates, missing, title;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
e.preventDefault();
e.stopImmediatePropagation();
e.stopPropagation();
return [4 /*yield*/, api.post({
action: "query",
redirects: "true",
generator: "links",
gplnamespace: "0",
gpllimit: "max",
prop: "templates",
tllimit: "max",
tlnamespace: "10",
tltemplates: wgPageName,
titles: wgPageName
})];
case 1:
result = _c.sent();
targetUl.empty();
if (!result.query) {
targetUl.text(wgULS("本模板未被任何条目嵌入", "本模板未被任何條目引用"));
}
else {
redirects_1 = Object.fromEntries((result.query.redirects || []).map(function (_a) {
var from = _a.from, to = _a.to;
return [from, to];
}));
_loop_1 = function (templates, missing, title) {
if (!Array.isArray(templates) && typeof missing === "undefined") {
var link = $("<a>", {
title: title,
text: title,
href: "/".concat(encodeURIComponent(title))
});
$("<li>").append(link).appendTo(targetUl);
$(generateSelector(title, redirects_1)).each(function (_, ele) {
if (ele.title.length > 0) {
ele.dataset.title = ele.title;
}
});
link.on("mouseenter", function () {
$(generateSelector(title, redirects_1)).css("background-color", "yellow");
});
link.on("mouseleave", function () {
$(generateSelector(title, redirects_1)).css("background-color", "");
});
}
};
for (_i = 0, _a = Object.values(result.query.pages); _i < _a.length; _i++) {
_b = _a[_i], templates = _b.templates, missing = _b.missing, title = _b.title;
_loop_1(templates, missing, title);
}
if (targetUl.children().length === 0) {
targetUl.text(wgULS("本模板所有条目均添加了本模板", "本模板所有條目均添加了本模板"));
}
}
targetLoc.show();
return [2 /*return*/];
}
});
}); }).trigger("click");
});
// </pre>