MediaWiki:Gadget-Site.js: Difference between revisions
Jump to navigation
Jump to search
m (1 revision imported) |
No edit summary |
||
| Line 1: | Line 1: | ||
var pageName = mw.config.get("wgPageName"); | |||
var ns = mw.config.get("wgNamespaceNumber"); | |||
/* ***** UpdateLanguageNameAndCode conditions ***** */ | |||
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" | |||
]; | |||
if (firstPara) { | |||
for (var i = 0; i < titlePrefixes.length; i++) { | |||
if (pageName.indexOf(titlePrefixes[i]) === 0) { | |||
importScript("MediaWiki:UpdateLanguageNameAndCode.js"); | |||
break; | |||
} | |||
} | |||
if ( | |||
importScript("MediaWiki: | |||
} | } | ||
/* ***** Google snippet hiding ***** */ | |||
var hideElems = document.querySelectorAll(".mw-editsection, #toc, #catlinks"); | |||
for (var k = 0; k < hideElems.length; k++) { | |||
var el = hideElems[k]; | |||
el.setAttribute("data-nosnippet", ""); | |||
if (navigator.userAgent.toLowerCase().indexOf("googlebot") !== -1) { | |||
el.style.display = "none"; | |||
/* ***** | |||
} | } | ||
} | } | ||
/* ***** | /* ***** Clean up "0 c" / "0 e" on category pages ***** */ | ||
var catElems = document.querySelectorAll(".CategoryTreeItem bdi + span"); | |||
for (var m = 0; m < catElems.length; m++) { | |||
var t = catElems[m]; | |||
t.textContent = t.textContent.replace("0 c, ", "").replace(", 0 e", ""); | |||
} | } | ||
/* ***** | /* ***** new-section-redirect ***** */ | ||
var newSectionRedirect = document.querySelector("#new-section-redirect a"); | |||
var newSectionButton = | |||
document.querySelector("#ca-addsection a") || | |||
document.getElementById("ca-addsection"); // fallback for ":is()" | |||
if (newSectionButton && newSectionRedirect) { | |||
if ( | |||
newSectionButton.href = newSectionRedirect.href; | newSectionButton.href = newSectionRedirect.href; | ||
} | |||
Latest revision as of 13:13, 15 November 2025
var pageName = mw.config.get("wgPageName");
var ns = mw.config.get("wgNamespaceNumber");
/* ***** UpdateLanguageNameAndCode conditions ***** */
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"
];
if (firstPara) {
for (var i = 0; i < titlePrefixes.length; i++) {
if (pageName.indexOf(titlePrefixes[i]) === 0) {
importScript("MediaWiki:UpdateLanguageNameAndCode.js");
break;
}
}
}
/* ***** Google snippet hiding ***** */
var hideElems = document.querySelectorAll(".mw-editsection, #toc, #catlinks");
for (var k = 0; k < hideElems.length; k++) {
var el = hideElems[k];
el.setAttribute("data-nosnippet", "");
if (navigator.userAgent.toLowerCase().indexOf("googlebot") !== -1) {
el.style.display = "none";
}
}
/* ***** Clean up "0 c" / "0 e" on category pages ***** */
var catElems = document.querySelectorAll(".CategoryTreeItem bdi + span");
for (var m = 0; m < catElems.length; m++) {
var t = catElems[m];
t.textContent = t.textContent.replace("0 c, ", "").replace(", 0 e", "");
}
/* ***** new-section-redirect ***** */
var newSectionRedirect = document.querySelector("#new-section-redirect a");
var newSectionButton =
document.querySelector("#ca-addsection a") ||
document.getElementById("ca-addsection"); // fallback for ":is()"
if (newSectionButton && newSectionRedirect) {
newSectionButton.href = newSectionRedirect.href;
}