|
|
| Line 1: |
Line 1: |
| // This gadget contains code that will run unconditionally for everyone - both on mobile and desktop.
| | var pageName = mw.config.get("wgPageName"); |
| // Consider instead adding your code to [[MediaWiki:Common.js]], [[MediaWiki:Mobile.js]], or a gadget.
| | var ns = mw.config.get("wgNamespaceNumber"); |
| // <nowiki>
| |
|
| |
|
| const pageName = mw.config.get("wgPageName");
| | /* ***** UpdateLanguageNameAndCode conditions ***** */ |
| const ns = mw.config.get("wgNamespaceNumber");
| | var firstPara = document.querySelector(".mw-parser-output p:first-of-type"); |
| | var titlePrefixes = [ |
| | "Module:languages/code_to_canonical_name", |
| | "Module:languages/canonical_names", |
| | "Module:etymology_languages/code_to_canonical_name", |
| | "Module:etymology_languages/canonical_names", |
| | "Module:families/code_to_canonical_name", |
| | "Module:families/canonical_names", |
| | "Module:scripts/code_to_canonical_name", |
| | "Module:scripts/canonical_names", |
| | "Module:Hani-sortkey/data/serialized" |
| | ]; |
|
| |
|
| /* ***** Page-specific code ***** */
| | if (firstPara) { |
| switch (pageName) {
| | for (var i = 0; i < titlePrefixes.length; i++) { |
| case "Wiktionary:Main_Page": // [[Wiktionary:Main_Page]] | | if (pageName.indexOf(titlePrefixes[i]) === 0) { |
| // Workaround for [[phab:T335552]].
| | importScript("MediaWiki:UpdateLanguageNameAndCode.js"); |
| document.querySelector(".mw-searchInput").autocapitalize = "off";
| | break; |
| break;
| | } |
| case "Wiktionary:Gadget_preferences": // [[Wiktionary:Gadget_preferences]]
| | } |
| if (mw.config.get("wgAction") === "view") | |
| importScript("MediaWiki:WiktGadgetPrefsPage.js"); // [[MediaWiki:WiktGadgetPrefsPage.js]] | |
| break;
| |
| case "MediaWiki:Gadgets-definition": // [[MediaWiki:Gadgets-definition]]
| |
| importScript("MediaWiki:BetterGadgetsDefinition.js"); // [[MediaWiki:BetterGadgetsDefinition.js]] | |
| break;
| |
| case "Special:Search": // [[Special:Search]] | |
| importScript("MediaWiki:FindTrans.js"); // [[MediaWiki:FindTrans.js]]
| |
| break;
| |
| case "Wiktionary:Fonts/list": // [[Wiktionary:Fonts/list]]
| |
| if (mw.config.get("wgAction") === "view")
| |
| importScript("MediaWiki:InteractiveFontList.js"); // [[MediaWiki:InteractiveFontList.js]]
| |
| break;
| |
| case "Wiktionary:Tracking":
| |
| importScript("MediaWiki:BrowseTrackingCats.js"); // [[MediaWiki:BrowseTrackingCats.js]]
| |
| } | | } |
|
| |
|
| if (
| | /* ***** Google snippet hiding ***** */ |
| document.querySelector(".mw-parser-output p:first-of-type") && [
| | var hideElems = document.querySelectorAll(".mw-editsection, #toc, #catlinks"); |
| "Module:languages/code_to_canonical_name",
| | for (var k = 0; k < hideElems.length; k++) { |
| "Module:languages/canonical_names",
| | var el = hideElems[k]; |
| "Module:etymology_languages/code_to_canonical_name",
| | el.setAttribute("data-nosnippet", ""); |
| "Module:etymology_languages/canonical_names",
| | if (navigator.userAgent.toLowerCase().indexOf("googlebot") !== -1) { |
| "Module:families/code_to_canonical_name",
| | el.style.display = "none"; |
| "Module:families/canonical_names",
| |
| "Module:scripts/code_to_canonical_name",
| |
| "Module:scripts/canonical_names",
| |
| "Module:Hani-sortkey/data/serialized",
| |
| ].some(title => pageName.startsWith(title))
| |
| )
| |
| importScript("MediaWiki:UpdateLanguageNameAndCode.js"); // [[MediaWiki:UpdateLanguageNameAndCode.js]]
| |
| | |
| /* ***** Append #English to all links in definition sense lines ***** */ | |
| // Run this code in the main or Reconstruction namespaces,
| |
| // and on the Main Page (for WOTD and FWOTD),
| |
| // and in the Appendix namespace when there is a lemma or non-lemma form category.
| |
| if (!window.noDefinitionLineFragmentAddition &&
| |
| (ns === 0 || ns === 118 || pageName === "Wiktionary:Main_Page" ||
| |
| (ns === 100 && document.querySelector("#catlinks [href$=lemmas], #catlinks [href$=non-lemma_forms]"))
| |
| )
| |
| ) {
| |
| // Look for links inside a numbered list (<ol> tag).
| |
| // Must use [lang|=en] rather than :lang(en) because, at least in Firefox, | |
| // :lang(en) always matches wherever it is put in a selector | |
| // because all text is within <html lang="en">.
| |
| for (const elem of document.querySelectorAll(".mw-parser-output ol a:not(.mw-parser-output [lang] a), .mw-parser-output ol [lang|=en] a")) { | |
| // Only append to local existing main-namespace links without an existing anchor
| |
| const href = elem.getAttribute("href");
| |
| if (href && !/[#?:]/.test(href) && href[1] !== "/")
| |
| elem.href += "#English";
| |
| } | | } |
| } | | } |
|
| |
|
| /* ***** New entry wizard ***** */ | | /* ***** Clean up "0 c" / "0 e" on category pages ***** */ |
| if (document.getElementById("necplaceholder"))
| | var catElems = document.querySelectorAll(".CategoryTreeItem bdi + span"); |
| importScript("MediaWiki:NewEntryWizard.js"); // [[MediaWiki:NewEntryWizard.js]]
| | for (var m = 0; m < catElems.length; m++) { |
| | | var t = catElems[m]; |
| /* ***** Hide certain parts of the page from Google snippets ***** */
| | t.textContent = t.textContent.replace("0 c, ", "").replace(", 0 e", ""); |
| // Not sure whether this is working...
| |
| for (const elem of document.querySelectorAll(".mw-editsection, #toc, #catlinks")) {
| |
| elem.setAttribute("data-nosnippet", "");
| |
| if (navigator.userAgent.toLowerCase().includes("googlebot"))
| |
| elem.style.display = "none";
| |
| } | | } |
|
| |
|
| /* ***** Clean up category pages showing "0 c" or "0 e", e.g. [[Category:Pages with entries]] ***** */ | | /* ***** new-section-redirect ***** */ |
| for (const elem of document.querySelectorAll(".CategoryTreeItem bdi + span"))
| | var newSectionRedirect = document.querySelector("#new-section-redirect a"); |
| elem.textContent = elem.textContent.replace("0 c, ", "").replace(", 0 e", ""); | | var newSectionButton = |
| | document.querySelector("#ca-addsection a") || |
| | document.getElementById("ca-addsection"); // fallback for ":is()" |
|
| |
|
| /* ***** Template gadget for [[Module:UnitTests]]: e.g. [[Module:vi/testcases]] ***** */
| | if (newSectionButton && newSectionRedirect) { |
| for (const corner of document.querySelectorAll(".unit-tests .unit-tests-img-corner"))
| |
| corner.addEventListener("click", () => corner.closest(".unit-tests").classList.toggle("unit-tests-hide-passing"));
| |
| | |
| /* ***** WikiHiero kludge: see [[phab:T210695]] ***** */
| |
| if (document.querySelector(".mw-hiero-outer")) | |
| importScript("MediaWiki:WikiHieroTempFix.js"); // [[MediaWiki:WikiHieroTempFix.js]]
| |
| | |
| /* ***** `#new-section-redirect` changes the URL for "Add topic" (e.g. for [[Wiktionary:Beer parlour]]) ***** */
| |
| const newSectionRedirect = document.querySelector("#new-section-redirect a");
| |
| const newSectionButton = document.querySelector("#ca-addsection:is(a), #ca-addsection a");
| |
| if (newSectionRedirect && newSectionButton)
| |
| newSectionButton.href = newSectionRedirect.href; | | newSectionButton.href = newSectionRedirect.href; |
| | | } |
| // </nowiki>
| |