注意:在您儲存之後您必須清除瀏覽器快取才可看到最新的變動。
?_=1來訪問最新頁面。
/*
GlobalUsageChecker.js
Made with ♥ by User:Leranjun
This user script is meant to be used on Moegirl Commons only.
*/
$(function() {
if (mw.config.get("wgSiteName") !== "萌娘共享" || mw.config.get("wgNamespaceNumber") !== 6) {
return;
}
mw.loader.using("oojs-ui-core").done(function() {
let button = new OO.ui.ButtonWidget({
label: "檢查主站鏈入",
flags: "progressive"
});
button.on("click", function() {
button.setDisabled(true);
const pageName = mw.config.get("wgPageName");
window.gucCallback = function(response) {
window.gucResponse = window.gucResponse || response;
const pages = response.query.pages;
let result = "未知錯誤。",
type = "error";
if (typeof pages["-1"] === "undefined") {
result = "錯誤:此頁面不是文件。";
type = "error";
} else if (typeof pages["-1"].fileusage !== "undefined") {
result = "警告:文件" + pageName + "於主站有鏈入。<a href=\"https://zh.moegirl.tw/Special:WhatLinksHere/" + pageName + "\">查看鏈入</a>";
type = "warn";
} else {
result = "文件" + pageName + "於主站無鏈入。";
type = "info";
}
mw.notify($("<span></span>").html(result), {
title: "Global Usage Checker",
type: type,
tag: "guc"
});
button.setDisabled(false);
};
if (typeof window.gucResponse === "undefined") {
let s = document.createElement("script");
s.src = "https://zh.moegirl.tw/api.php?action=query&format=json&prop=fileusage&fulimit=1&titles=" + pageName + "&callback=gucCallback";
$("body").append(s);
} else {
gucCallback(window.gucResponse);
}
});
$("#filelinks").after(button.$element);
});
});