利用者:Kohaku2005/checkDisambig.js
表示
お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。
多くの Windows や Linux のブラウザ
- Ctrl を押しながら F5 を押す。
Mac における Safari
Mac における Chrome や Firefox
- ⌘ Cmd と ⇧ Shift を押しながら R を押す。
詳細についてはWikipedia:キャッシュを消すをご覧ください。
// @ts-check
(() => {
const createButton = () => {
const button = document.createElement("div");
button.innerText = "disambig";
button.setAttribute("role", "button");
button.style.padding = "1px";
button.style.display = "inline-block";
button.style.margin = "0 3px";
button.style.lineHeight = "1.2em";
/**
* @param [event] { MouseEvent }
* @returns { Promise<void> }
*/
const check = async (event) => {
if (button.style.border === "1px dashed black") return;
button.style.position = "";
button.style.right = "";
button.style.top = "";
if (disambigs[currentStep]) {
disambigs[currentStep].style.background = "";
}
if (event) {
event.preventDefault();
button.setAttribute("aria-disabled", "true");
button.setAttribute("title", "loading...");
button.style.cursor = "default";
button.style.textDecoration = "none";
button.style.color = "black";
button.style.background = "none";
button.style.border = "1px dashed black";
await new Promise(r => setTimeout(r, 500));
button.style.border = "";
}
disambigs = /** @type { HTMLElement[] } */([...document.querySelectorAll(".mw-disambig:not(.hatnote .mw-disambig)")]);
currentStep = -1;
if (disambigs.length) {
button.setAttribute("title", `(- / ${disambigs.length}) Right click to reload`);
button.removeAttribute("aria-disabled");
button.style.cursor = "pointer";
button.style.textDecoration = "none";
button.style.color = "white";
button.style.background = "red";
} else {
button.setAttribute("title", `(not found) Right click to reload`);
button.setAttribute("aria-disabled", "true");
button.style.cursor = "default";
button.style.textDecoration = "line-through";
button.style.color = "gray";
button.style.background = "none";
}
};
button.addEventListener("contextmenu", (e) => check(e));
/**
* @type { HTMLElement[] }
*/
let disambigs = [];
let currentStep = -1;
button.addEventListener("click", () => {
if (button.getAttribute("aria-disabled") === "true") return;
button.style.position = "fixed";
button.style.right = "10px";
button.style.top = "10px";
if (disambigs[currentStep]) {
disambigs[currentStep].style.background = "";
}
currentStep++;
if (currentStep + 1 > disambigs.length) {
currentStep = 0;
}
const target = disambigs[currentStep];
if (!target) return;
button.setAttribute("title", `(${currentStep + 1} / ${disambigs.length}) Right click to reload`);
target.scrollIntoView({ block: "center" });
target.style.background = "#e0e2ff";
});
check();
return button;
};
let button = createButton();
const indicators = document.querySelector(".mw-indicators");
if (indicators) {
indicators.append(button);
new MutationObserver(() => {
if (document.contains(indicators), !indicators.contains(button)) {
button = createButton();
indicators.append(button);
}
}).observe(indicators, { subtree: true, childList: true });
}
})();