MediaWiki:Common.js: diferenças entre revisões
Aparência
Sem resumo de edição |
Sem resumo de edição |
||
| Linha 8: | Linha 8: | ||
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"; | |||
} | |||
} | } | ||
| Linha 32: | Linha 41: | ||
var content = container.nextElementSibling; | var content = container.nextElementSibling; | ||
if (!content) return; | /* fallback caso o conteúdo já não esteja logo a seguir */ | ||
if ( | |||
!content || | |||
content.classList.contains("list-equip") | |||
) { | |||
content = container.parentElement.querySelector( | |||
".tab-glob, .tabber-container, .equip-content, .mw-collapsible" | |||
); | |||
} | |||
if (!content || content === container) return; | |||
switchButton.addEventListener("click", function () { | switchButton.addEventListener("click", function () { | ||
| Linha 39: | Linha 58: | ||
}); | }); | ||
} | } | ||
/* Enlève l'animation de chargement et affiche le contenu de la page lorsque c'est nécessaire */ | /* Enlève l'animation de chargement et affiche le contenu de la page lorsque c'est nécessaire */ | ||
function removeLoadingAnimation() { | function removeLoadingAnimation() { | ||
| Linha 68: | Linha 88: | ||
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 91: | Linha 111: | ||
document.documentElement.scrollTo({ | document.documentElement.scrollTo({ | ||
top: 0, | top: 0, | ||
behavior: "smooth", | |||
}); | }); | ||
}); | }); | ||
| Linha 99: | Linha 120: | ||
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 130: | Linha 151: | ||
"div#mw-content-text .list-equip" | "div#mw-content-text .list-equip" | ||
); | ); | ||
/* Lista de equipamentos */ | |||
equipmentContainer.forEach(function (container) { | equipmentContainer.forEach(function (container) { | ||
changeEquipementDisplay(container); | changeEquipementDisplay(container); | ||
| Linha 165: | Linha 187: | ||
if (firstScriptName === "Element") { | if (firstScriptName === "Element") { | ||
scriptsToLoad.shift() | scriptsToLoad.shift(); | ||
$.getScript(urlStart + firstScriptName + urlEnd, function () { | $.getScript(urlStart + firstScriptName + urlEnd, function () { | ||
injectCustomElements(); | injectCustomElements(); | ||
Revisão das 20h50min 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
===================================== */
/* Tabber helpers */
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 changeEquipementDisplay(container) {
var switchButton = container.querySelector(".button");
if (!switchButton) return;
var content = container.nextElementSibling;
/* fallback caso o conteúdo já não esteja logo a seguir */
if (
!content ||
content.classList.contains("list-equip")
) {
content = container.parentElement.querySelector(
".tab-glob, .tabber-container, .equip-content, .mw-collapsible"
);
}
if (!content || content === container) return;
switchButton.addEventListener("click", function () {
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) {
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();
}
/* =======================================
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"
);
/* Lista de equipamentos */
equipmentContainer.forEach(function (container) {
changeEquipementDisplay(container);
});
/* Carrega scripts específicos dependendo da página */
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 () {
injectCustomElements();
loadNextScripts();
});
} else {
loadNextScripts();
}
}
function loadNextScripts() {
scriptsToLoad.forEach(function (scriptName) {
mw.loader.load(urlStart + scriptName + urlEnd);
});
removeLoadingAnimation();
}
}
if (mw.config.get("wgUserName")) {
mw.loader.load(urlStart + "Redactor" + urlEnd);
}
addButtonTop();
buttonTop();
cookies();
})();