MediaWiki:Common.js: diferenças entre revisões
Aparência
Sem resumo de edição |
Sem resumo de edição |
||
| (Há 4 edições intermédias do mesmo utilizador que não estão a ser apresentadas) | |||
| Linha 1: | Linha 1: | ||
/* Código Javascript colocado aqui será carregado para todos os utilizadores em cada carregamento de página */ | |||
/* ===================================== | |||
FUNÇÕES AUXILIARES | |||
===================================== */ | |||
function showElement(element) { | |||
if (element) { | |||
element.classList.remove("tabber-noactive"); | |||
} | |||
} | |||
function hideElement(element) { | |||
if (element) { | |||
element.classList.add("tabber-noactive"); | |||
} | |||
} | |||
function toggleElement(element) { | |||
if (element) { | |||
element.classList.toggle("tabber-noactive"); | |||
} | |||
} | |||
/* Favicon */ | |||
function fixInsecureFavicon() { | |||
var favicon = document.querySelector('link[rel="shortcut icon"]'); | |||
if (favicon) { | |||
favicon.href = | |||
"https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico"; | |||
} | |||
} | |||
/* Liste des équipements */ | |||
function findEquipContent(container) { | |||
var parent = container.parentElement; | |||
if (!parent) return null; | |||
/* 1) caso antigo: logo a seguir */ | |||
}); | var next = container.nextElementSibling; | ||
if (next && !next.classList.contains("list-equip")) { | |||
return next; | |||
} | |||
/* 2) procurar dentro do mesmo bloco pai */ | |||
var candidates = parent.children; | |||
var foundCurrent = false; | |||
for (var i = 0; i < candidates.length; i++) { | |||
var el = candidates[i]; | |||
if (el === container) { | |||
foundCurrent = true; | |||
continue; | |||
} | |||
if (!foundCurrent) continue; | |||
if ( | |||
el.matches && | |||
el.matches(".tab-glob, .tabber-container, .equip-content, .mw-collapsible, .tabber-noactive") | |||
) { | |||
return el; | |||
} | |||
} | |||
/* 3) fallback largo */ | |||
return parent.querySelector( | |||
".tab-glob, .tabber-container, .equip-content, .mw-collapsible" | |||
); | |||
} | |||
function changeEquipementDisplay(container) { | |||
var switchButton = container.querySelector(".button"); | |||
if (!switchButton) return; | |||
var content = findEquipContent(container); | |||
if (!content || content === container) return; | |||
switchButton.addEventListener("click", function (ev) { | |||
ev.preventDefault(); | |||
switchButton.classList.toggle("tabber-active"); | |||
content.classList.toggle("tabber-noactive"); | |||
}); | |||
} | |||
/* Enlève l'animation de chargement et affiche le contenu de la page lorsque c'est nécessaire */ | |||
function removeLoadingAnimation() { | |||
var loadingAnimation = document.getElementById("loading-animation"); | |||
var showAfterLoading = document.getElementById("show-after-loading"); | |||
if (loadingAnimation) { | |||
hideElement(loadingAnimation); | |||
} | |||
if (showAfterLoading) { | |||
showElement(showAfterLoading); | |||
} | |||
} | |||
/* BOUTON RETOUR VERS LE HAUT */ | |||
function addButtonTop() { | |||
var contentText = document.querySelector("div#mw-content-text"); | |||
if (contentText !== null && !contentText.querySelector(".top-button")) { | |||
var divButtonTop = document.createElement("div"); | |||
divButtonTop.classList.add("top-button"); | |||
contentText.appendChild(divButtonTop); | |||
} | |||
} | |||
function buttonTop() { | |||
var balise = document.querySelector("div#mw-page-header-links"); | |||
var topButton = document.querySelector(".top-button"); | |||
if (balise !== null && topButton !== null) { | |||
var options = { | |||
root: null, | |||
rootMargin: "0px", | |||
threshold: 0, | |||
}; | |||
var observer = new IntersectionObserver(callback, options); | |||
observer.observe(balise); | |||
function callback(entries) { | |||
entries.forEach(function (entry) { | |||
if (entry.isIntersecting) { | |||
topButton.classList.remove("show-button"); | |||
} else { | |||
topButton.classList.add("show-button"); | |||
} | |||
}); | |||
} | |||
topButton.addEventListener("click", function () { | |||
document.documentElement.scrollTo({ | |||
top: 0, | |||
behavior: "smooth", | |||
}); | |||
}); | |||
} | |||
} | |||
/* Cookies */ | |||
function cookies() { | |||
var req = new XMLHttpRequest(); | |||
req.addEventListener("load", function () { | |||
if (this.status >= 200 && this.status < 300) { | |||
var data = JSON.parse(this.responseText); | |||
if (data.hasOwnProperty("version")) { | |||
var gdpr = document.createElement("script"); | |||
gdpr.src = | |||
"https://s3-static.geo.gfsrv.net/cookiebanner/" + | |||
data.version + | |||
"/cookie.min.js"; | |||
document.head.appendChild(gdpr); | |||
} | |||
} | |||
}); | |||
req.open("GET", "https://s3-static.geo.gfsrv.net/cookiebanner/version.json"); | |||
req.send(); | |||
} | |||
function initCollapsibles() { | |||
mw.loader.using("jquery.makeCollapsible").then(function () { | |||
$(".mw-collapsible").makeCollapsible(); | |||
}); | |||
} | |||
/* ======================================= | |||
FUNÇÃO GLOBAL – corre ao carregar a página | |||
======================================= */ | |||
(function () { | |||
fixInsecureFavicon(); | |||
var urlStart = "/index.php?title=MediaWiki:Script/"; | |||
var urlEnd = ".js&action=raw&ctype=text/javascript"; | |||
var loadScripts = document.querySelectorAll("div[data-load-javascript]"); | |||
var equipmentContainer = document.querySelectorAll( | |||
"div#mw-content-text .list-equip" | |||
); | |||
equipmentContainer.forEach(function (container) { | |||
changeEquipementDisplay(container); | |||
}); | |||
if (loadScripts.length) { | |||
var allowedScripts = { | |||
Tabber: true, | |||
Skills: true, | |||
Modal: true, | |||
Switch: true, | |||
Loot: true, | |||
Map: true, | |||
Filter: true, | |||
Calculator: true, | |||
Element: true, | |||
Pets: true, | |||
Colorblind: true, | |||
}; | |||
var scriptsToLoad = []; | |||
loadScripts.forEach(function (scriptElement) { | |||
var scriptName = scriptElement.dataset.loadJavascript; | |||
if (allowedScripts[scriptName]) { | |||
allowedScripts[scriptName] = false; | |||
scriptsToLoad.push(scriptName); | |||
} | |||
}); | |||
if (scriptsToLoad.length) { | |||
var firstScriptName = scriptsToLoad[0]; | |||
if (firstScriptName === "Element") { | |||
scriptsToLoad.shift(); | |||
$.getScript(urlStart + firstScriptName + urlEnd, function () { | |||
if (typeof injectCustomElements === "function") { | |||
injectCustomElements(); | |||
} | |||
loadNextScripts(); | |||
}); | |||
} else { | |||
loadNextScripts(); | |||
} | |||
} else { | |||
removeLoadingAnimation(); | |||
initCollapsibles(); | |||
} | |||
function loadNextScripts() { | |||
scriptsToLoad.forEach(function (scriptName) { | |||
mw.loader.load(urlStart + scriptName + urlEnd); | |||
}); | |||
removeLoadingAnimation(); | |||
initCollapsibles(); | |||
} | |||
} else { | |||
initCollapsibles(); | |||
} | |||
if (mw.config.get("wgUserName")) { | |||
mw.loader.load(urlStart + "Redactor" + urlEnd); | |||
} | |||
addButtonTop(); | |||
buttonTop(); | |||
cookies(); | |||
})(); | |||
Edição atual desde as 21h25min de 29 de março de 2026
/* Código Javascript colocado aqui será carregado para todos os utilizadores em cada carregamento de página */
/* =====================================
FUNÇÕES AUXILIARES
===================================== */
function showElement(element) {
if (element) {
element.classList.remove("tabber-noactive");
}
}
function hideElement(element) {
if (element) {
element.classList.add("tabber-noactive");
}
}
function toggleElement(element) {
if (element) {
element.classList.toggle("tabber-noactive");
}
}
/* Favicon */
function fixInsecureFavicon() {
var favicon = document.querySelector('link[rel="shortcut icon"]');
if (favicon) {
favicon.href =
"https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
}
}
/* Liste des équipements */
function findEquipContent(container) {
var parent = container.parentElement;
if (!parent) return null;
/* 1) caso antigo: logo a seguir */
var next = container.nextElementSibling;
if (next && !next.classList.contains("list-equip")) {
return next;
}
/* 2) procurar dentro do mesmo bloco pai */
var candidates = parent.children;
var foundCurrent = false;
for (var i = 0; i < candidates.length; i++) {
var el = candidates[i];
if (el === container) {
foundCurrent = true;
continue;
}
if (!foundCurrent) continue;
if (
el.matches &&
el.matches(".tab-glob, .tabber-container, .equip-content, .mw-collapsible, .tabber-noactive")
) {
return el;
}
}
/* 3) fallback largo */
return parent.querySelector(
".tab-glob, .tabber-container, .equip-content, .mw-collapsible"
);
}
function changeEquipementDisplay(container) {
var switchButton = container.querySelector(".button");
if (!switchButton) return;
var content = findEquipContent(container);
if (!content || content === container) return;
switchButton.addEventListener("click", function (ev) {
ev.preventDefault();
switchButton.classList.toggle("tabber-active");
content.classList.toggle("tabber-noactive");
});
}
/* Enlève l'animation de chargement et affiche le contenu de la page lorsque c'est nécessaire */
function removeLoadingAnimation() {
var loadingAnimation = document.getElementById("loading-animation");
var showAfterLoading = document.getElementById("show-after-loading");
if (loadingAnimation) {
hideElement(loadingAnimation);
}
if (showAfterLoading) {
showElement(showAfterLoading);
}
}
/* BOUTON RETOUR VERS LE HAUT */
function addButtonTop() {
var contentText = document.querySelector("div#mw-content-text");
if (contentText !== null && !contentText.querySelector(".top-button")) {
var divButtonTop = document.createElement("div");
divButtonTop.classList.add("top-button");
contentText.appendChild(divButtonTop);
}
}
function buttonTop() {
var balise = document.querySelector("div#mw-page-header-links");
var topButton = document.querySelector(".top-button");
if (balise !== null && topButton !== null) {
var options = {
root: null,
rootMargin: "0px",
threshold: 0,
};
var observer = new IntersectionObserver(callback, options);
observer.observe(balise);
function callback(entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
topButton.classList.remove("show-button");
} else {
topButton.classList.add("show-button");
}
});
}
topButton.addEventListener("click", function () {
document.documentElement.scrollTo({
top: 0,
behavior: "smooth",
});
});
}
}
/* Cookies */
function cookies() {
var req = new XMLHttpRequest();
req.addEventListener("load", function () {
if (this.status >= 200 && this.status < 300) {
var data = JSON.parse(this.responseText);
if (data.hasOwnProperty("version")) {
var gdpr = document.createElement("script");
gdpr.src =
"https://s3-static.geo.gfsrv.net/cookiebanner/" +
data.version +
"/cookie.min.js";
document.head.appendChild(gdpr);
}
}
});
req.open("GET", "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
req.send();
}
function initCollapsibles() {
mw.loader.using("jquery.makeCollapsible").then(function () {
$(".mw-collapsible").makeCollapsible();
});
}
/* =======================================
FUNÇÃO GLOBAL – corre ao carregar a página
======================================= */
(function () {
fixInsecureFavicon();
var urlStart = "/index.php?title=MediaWiki:Script/";
var urlEnd = ".js&action=raw&ctype=text/javascript";
var loadScripts = document.querySelectorAll("div[data-load-javascript]");
var equipmentContainer = document.querySelectorAll(
"div#mw-content-text .list-equip"
);
equipmentContainer.forEach(function (container) {
changeEquipementDisplay(container);
});
if (loadScripts.length) {
var allowedScripts = {
Tabber: true,
Skills: true,
Modal: true,
Switch: true,
Loot: true,
Map: true,
Filter: true,
Calculator: true,
Element: true,
Pets: true,
Colorblind: true,
};
var scriptsToLoad = [];
loadScripts.forEach(function (scriptElement) {
var scriptName = scriptElement.dataset.loadJavascript;
if (allowedScripts[scriptName]) {
allowedScripts[scriptName] = false;
scriptsToLoad.push(scriptName);
}
});
if (scriptsToLoad.length) {
var firstScriptName = scriptsToLoad[0];
if (firstScriptName === "Element") {
scriptsToLoad.shift();
$.getScript(urlStart + firstScriptName + urlEnd, function () {
if (typeof injectCustomElements === "function") {
injectCustomElements();
}
loadNextScripts();
});
} else {
loadNextScripts();
}
} else {
removeLoadingAnimation();
initCollapsibles();
}
function loadNextScripts() {
scriptsToLoad.forEach(function (scriptName) {
mw.loader.load(urlStart + scriptName + urlEnd);
});
removeLoadingAnimation();
initCollapsibles();
}
} else {
initCollapsibles();
}
if (mw.config.get("wgUserName")) {
mw.loader.load(urlStart + "Redactor" + urlEnd);
}
addButtonTop();
buttonTop();
cookies();
})();