MediaWiki:Gadget-JumpToError.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// <nowiki>
(async () => {

const errors = document.querySelectorAll(".scribunto-error");
if (errors.length) {
	const message = document.createElement("span");
	message.id = "jump-to-scribunto-error";
	message.textContent = `Warning: this page has ${errors.length} Lua error${errors.length === 1 ? "" : "s"}; click here to jump to the error`;
	await mw.notify(message);
	requestAnimationFrame(() => document.querySelector("#jump-to-scribunto-error").addEventListener("click", () => {
		// open navframes etc.
		const firstError = errors[0];

		const nav = firstError.closest(".NavContent");
		if (nav && nav.style.display === "none")
			nav.previousElementSibling.click();

		const mwCollapsed = firstError.closest(".mw-collapsed");
		if (mwCollapsed)
			mwCollapsed.querySelector(".mw-collapsible-toggle-collapsed").click();

		const vs = firstError.closest(".vsShow, .vsHide");
		if (vs && vs.style.display === "none")
			vs.closest(".vsSwitcher").querySelector(`[role="button"]`).click();

		const nym = firstError.closest("[data-relation-class]");
		if (nym && nym.closest("dl").style.display === "none")
			[...nym.closest("li").querySelectorAll(".nyms-toggle > a")].find(elem =>
				elem.textContent.includes(nym.getAttribute("data-relation-class"))).click();

		const quotes = firstError.closest(".wikt-quote-container");
		if (quotes && quotes.style.display === "none")
			quotes.parentElement.querySelector(`.HQToggle > a`).click();

		requestAnimationFrame(() => firstError.scrollIntoView({block: "center"}));
	}));
}

})();
// </nowiki>