MediaWiki:Common.js: diferenças entre revisões
Aparência
Sem resumo de edição |
Sem resumo de edição |
||
| (Há 3 edições intermédias do mesmo utilizador que não estão a ser apresentadas) | |||
| Linha 4: | Linha 4: | ||
FUNÇÕES AUXILIARES | FUNÇÕES AUXILIARES | ||
===================================== */ | ===================================== */ | ||
function showElement(element) { | function showElement(element) { | ||
element.classList.remove("tabber-noactive"); | if (element) { | ||
element.classList.remove("tabber-noactive"); | |||
} | |||
} | } | ||
function hideElement(element) { | function hideElement(element) { | ||
element.classList.add("tabber-noactive"); | if (element) { | ||
element.classList.add("tabber-noactive"); | |||
} | |||
} | } | ||
function toggleElement(element) { | function toggleElement(element) { | ||
element.classList.toggle("tabber-noactive"); | if (element) { | ||
element.classList.toggle("tabber-noactive"); | |||
} | |||
} | } | ||
/* Favicon */ | /* Favicon */ | ||
function fixInsecureFavicon() { | function fixInsecureFavicon() { | ||
document.querySelector('link[rel="shortcut icon"]').href = | var favicon = document.querySelector('link[rel="shortcut icon"]'); | ||
if (favicon) { | |||
favicon.href = | |||
"https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico"; | |||
} | |||
} | } | ||
/* Liste des équipements */ | /* 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) { | function changeEquipementDisplay(container) { | ||
var switchButton = container.querySelector(".button"); | var switchButton = container.querySelector(".button"); | ||
var content = container | if (!switchButton) return; | ||
var content = findEquipContent(container); | |||
if (!content || content === container) return; | |||
switchButton.addEventListener("click", function () { | switchButton.addEventListener("click", function (ev) { | ||
ev.preventDefault(); | |||
switchButton.classList.toggle("tabber-active"); | switchButton.classList.toggle("tabber-active"); | ||
content.classList.toggle("tabber-noactive"); | |||
}); | }); | ||
} | } | ||
| Linha 54: | Linha 103: | ||
var contentText = document.querySelector("div#mw-content-text"); | var contentText = document.querySelector("div#mw-content-text"); | ||
if (contentText !== null) { | if (contentText !== null && !contentText.querySelector(".top-button")) { | ||
var divButtonTop = document.createElement("div"); | var divButtonTop = document.createElement("div"); | ||
divButtonTop.classList.add("top-button"); | divButtonTop.classList.add("top-button"); | ||
| Linha 65: | Linha 114: | ||
var topButton = document.querySelector(".top-button"); | var topButton = document.querySelector(".top-button"); | ||
if (balise !== null) { | if (balise !== null && topButton !== null) { | ||
var options = { | var options = { | ||
root: null, | root: null, | ||
| Linha 88: | Linha 137: | ||
document.documentElement.scrollTo({ | document.documentElement.scrollTo({ | ||
top: 0, | top: 0, | ||
behavior: "smooth", | |||
}); | }); | ||
}); | }); | ||
| Linha 96: | Linha 146: | ||
function cookies() { | function cookies() { | ||
var req = new XMLHttpRequest(); | var req = new XMLHttpRequest(); | ||
req.addEventListener("load", function ( | req.addEventListener("load", function () { | ||
if (this.status >= 200 && this.status < 300) { | if (this.status >= 200 && this.status < 300) { | ||
var data = JSON.parse(this.responseText); | var data = JSON.parse(this.responseText); | ||
| Linha 111: | Linha 161: | ||
req.open("GET", "https://s3-static.geo.gfsrv.net/cookiebanner/version.json"); | req.open("GET", "https://s3-static.geo.gfsrv.net/cookiebanner/version.json"); | ||
req.send(); | req.send(); | ||
} | |||
function initCollapsibles() { | |||
mw.loader.using("jquery.makeCollapsible").then(function () { | |||
$(".mw-collapsible").makeCollapsible(); | |||
}); | |||
} | } | ||
| Linha 127: | Linha 183: | ||
"div#mw-content-text .list-equip" | "div#mw-content-text .list-equip" | ||
); | ); | ||
equipmentContainer.forEach(function (container) { | equipmentContainer.forEach(function (container) { | ||
changeEquipementDisplay(container); | changeEquipementDisplay(container); | ||
}); | }); | ||
if (loadScripts.length) { | if (loadScripts.length) { | ||
var allowedScripts = { | var allowedScripts = { | ||
| Linha 162: | Linha 217: | ||
if (firstScriptName === "Element") { | if (firstScriptName === "Element") { | ||
scriptsToLoad.shift() | scriptsToLoad.shift(); | ||
$.getScript(urlStart + firstScriptName + urlEnd, function () { | $.getScript(urlStart + firstScriptName + urlEnd, function () { | ||
injectCustomElements(); | if (typeof injectCustomElements === "function") { | ||
injectCustomElements(); | |||
} | |||
loadNextScripts(); | loadNextScripts(); | ||
}); | }); | ||
| Linha 170: | Linha 227: | ||
loadNextScripts(); | loadNextScripts(); | ||
} | } | ||
} else { | |||
removeLoadingAnimation(); | |||
initCollapsibles(); | |||
} | } | ||
| Linha 178: | Linha 238: | ||
removeLoadingAnimation(); | removeLoadingAnimation(); | ||
initCollapsibles(); | |||
} | } | ||
} else { | |||
initCollapsibles(); | |||
} | } | ||
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();
})();