MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
| (4 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
| Linha 116: | Linha 116: | ||
/* --- Tradutor no TOPO da Barra Lateral com Bandeiras Oficiais (ES5) --- */ | |||
/* --- Tradutor no TOPO da Barra Lateral com Bandeiras Oficiais (ES5) --- */ | |||
/* --- Tradutor | |||
$(document).ready(function() { | $(document).ready(function() { | ||
var defaultLang = 'pt'; | var defaultLang = 'pt'; | ||
| Linha 135: | Linha 134: | ||
} | } | ||
// 2 | // 2. Injeta o menu com as bandeiras ANTES do menu principal de Navegação | ||
if ($('#p-lang-custom').length === 0) { | |||
var menuHTML = '<nav class="portal vector-menu vector-menu-portal" id="p-lang-custom" style="text-align:center; padding: 10px 0;">' + | |||
'<div class="body vector-menu-content" style="display:flex; justify-content:center; gap:8px;">' + | |||
'<a href="#" class="lang-btn" data-lang="pt" style="text-decoration:none;" title="Português (Brasil)"><img src="https://otpokemon.com/images/flags/br.png" width="30px"/></a>' + | |||
'<a href="#" class="lang-btn" data-lang="en" style="text-decoration:none;" title="English"><img src="https://otpokemon.com/images/flags/en.png" width="30px"/></a>' + | |||
'<a href="#" class="lang-btn" data-lang="es" style="text-decoration:none;" title="Español"><img src="https://otpokemon.com/images/flags/es.png" width="30px"/></a>' + | |||
if ( | '<a href="#" class="lang-btn" data-lang="pl" style="text-decoration:none;" title="Polski"><img src="https://otpokemon.com/images/flags/pl.png" width="30px"/></a>' + | ||
var menuHTML = '< | |||
'<div class="body vector-menu-content | |||
'</div>' + | '</div>' + | ||
'</ | '</nav>'; | ||
// Procura o menu "Navegação" e insere o de idiomas logo ACIMA dele | |||
if ($('#p-navigation').length > 0) { | |||
$('#p-navigation').before(menuHTML); | |||
} else { | |||
// Plano B de segurança, caso a página carregue de forma diferente | |||
$('#mw-panel').prepend(menuHTML); | |||
} | |||
} | } | ||
// | // 3. Lógica de tradução melhorada | ||
$(document).on('click', '.lang-btn', function(e) { | $(document).on('click', '.lang-btn', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
| Linha 166: | Linha 160: | ||
var select = document.querySelector('.goog-te-combo'); | var select = document.querySelector('.goog-te-combo'); | ||
// Se clicar em Português, forçamos a limpeza profunda dos cookies | |||
if (targetLang === defaultLang) { | if (targetLang === defaultLang) { | ||
var host = location.hostname; | |||
// Limpa o cookie na raiz | |||
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; | document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; | ||
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=" + | // Limpa o cookie no domínio exato | ||
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=" + host + ";"; | |||
// Limpa o cookie com o prefixo de ponto (muito usado pelo Google) | |||
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=." + host + ";"; | |||
// Se for um subdomínio (ex: wiki.otpokemon.com), limpa também o domínio principal (.otpokemon.com) | |||
var parts = host.split('.'); | |||
if (parts.length > 2) { | |||
var mainDomain = "." + parts[parts.length - 2] + "." + parts[parts.length - 1]; | |||
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=" + mainDomain + ";"; | |||
} | |||
// Recarrega a página para aplicar a limpeza | |||
location.reload(); | location.reload(); | ||
return; | return; | ||
} | } | ||
// Se clicar num idioma estrangeiro, chama o Google Translate | |||
if (select) { | if (select) { | ||
select.value = targetLang; | select.value = targetLang; | ||
var event; | var event; | ||
if (typeof Event === 'function') { | if (typeof Event === 'function') { | ||
| Linha 185: | Linha 195: | ||
select.dispatchEvent(event); | select.dispatchEvent(event); | ||
} else { | } else { | ||
alert('O | alert('O sistema de tradução ainda está a carregar. Por favor, aguarde um instante e tente novamente.'); | ||
} | } | ||
}); | }); | ||
}); | }); | ||
Edição atual tal como às 12h54min de 7 de março de 2026
var coll1 = document.getElementsByClassName("collapsible-battle-pass");
var coll2 = document.getElementsByClassName("collapsible-pokemon");
function toggleContent(clickedButton, contentToToggle) {
var allContents = document.getElementsByClassName("content");
for (var j = 0; j < allContents.length; j++) {
allContents[j].style.maxHeight = null;
}
var allButtons = document.getElementsByClassName("collapsible-battle-pass");
for (var k = 0; k < allButtons.length; k++) {
allButtons[k].classList.remove("active");
}
allButtons = document.getElementsByClassName("collapsible-pokemon");
for (var k = 0; k < allButtons.length; k++) {
allButtons[k].classList.remove("active");
}
if (contentToToggle.style.maxHeight) {
contentToToggle.style.maxHeight = null;
} else {
contentToToggle.style.maxHeight = contentToToggle.scrollHeight + "px";
}
clickedButton.classList.add("active");
}
for (var i = 0; i < coll1.length; i++) {
coll1[i].addEventListener("click", function() {
var content = this.nextElementSibling;
toggleContent(this, content);
});
}
for (var i = 0; i < coll2.length; i++) {
coll2[i].addEventListener("click", function() {
var content = this.nextElementSibling;
toggleContent(this, content);
});
}
/* Pokedex */
var coll3 = document.getElementsByClassName("collapsible-pokedex");
function toggleContent(clickedButton, contentToToggle) {
var allContents = document.getElementsByClassName("content");
for (var j = 0; j < allContents.length; j++) {
allContents[j].style.maxHeight = null;
}
var allButtons2 = document.getElementsByClassName("collapsible-pokedex");
for (var k = 0; k < allButtons2.length; k++) {
allButtons2[k].classList.remove("active");
}
if (contentToToggle.style.maxHeight) {
contentToToggle.style.maxHeight = null;
} else {
contentToToggle.style.maxHeight = contentToToggle.scrollHeight + "px";
}
clickedButton.classList.add("active");
}
for (var i = 0; i < coll3.length; i++) {
coll3[i].addEventListener("click", function() {
var content = this.nextElementSibling;
toggleContent(this, content);
});
}
/* Pokedex */
function toggleShinyList() {
var shinyList = document.getElementById("shiny-list");
if (shinyList.style.display === "none" || shinyList.style.display === "") {
shinyList.style.display = "block";
} else {
shinyList.style.display = "flex";
}
}
mw.loader.using('jquery', function () {
$(document).ready(function () {
var isAscending = true;
var $sortButton = $('<div class="sort-button" style="width: 60px; height: 50px; background-image: url(https://wiki.otpokemon.com/images/9/92/O-c.png); background-position: center; background-repeat: no-repeat; background-size: cover; border-radius: 3px; cursor: pointer; float: right; margin-right: 0.5%;margin-top: -50px;"></div>');
$('.square-div-shiny').before($sortButton);
$sortButton.on('click', function () {
var $container = $('.square-div-shiny');
var $boxes = $container.children('.square-box-shiny');
$boxes.sort(function (a, b) {
var numA = parseInt($(a).find('.square-name-shiny').text().match(/\d+/)[0], 10);
var numB = parseInt($(b).find('.square-name-shiny').text().match(/\d+/)[0], 10);
return isAscending ? numA - numB : numB - numA;
});
$container.append($boxes);
isAscending = !isAscending;
var newImage = isAscending
? 'https://wiki.otpokemon.com/images/e/e2/O-d.png'
: 'https://wiki.otpokemon.com/images/9/92/O-c.png';
$sortButton.css('background-image', 'url(' + newImage + ')');
});
});
});
/* --- Tradutor no TOPO da Barra Lateral com Bandeiras Oficiais (ES5) --- */
/* --- Tradutor no TOPO da Barra Lateral com Bandeiras Oficiais (ES5) --- */
$(document).ready(function() {
var defaultLang = 'pt';
// 1. Carrega o Google Translate invisível
if ($('#google_translate_element').length === 0) {
$('body').append('<div id="google_translate_element" style="display:none;"></div>');
window.googleTranslateElementInit = function() {
new google.translate.TranslateElement({
pageLanguage: defaultLang,
includedLanguages: 'pt,en,es,pl',
autoDisplay: false
}, 'google_translate_element');
};
$.getScript("https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");
}
// 2. Injeta o menu com as bandeiras ANTES do menu principal de Navegação
if ($('#p-lang-custom').length === 0) {
var menuHTML = '<nav class="portal vector-menu vector-menu-portal" id="p-lang-custom" style="text-align:center; padding: 10px 0;">' +
'<div class="body vector-menu-content" style="display:flex; justify-content:center; gap:8px;">' +
'<a href="#" class="lang-btn" data-lang="pt" style="text-decoration:none;" title="Português (Brasil)"><img src="https://otpokemon.com/images/flags/br.png" width="30px"/></a>' +
'<a href="#" class="lang-btn" data-lang="en" style="text-decoration:none;" title="English"><img src="https://otpokemon.com/images/flags/en.png" width="30px"/></a>' +
'<a href="#" class="lang-btn" data-lang="es" style="text-decoration:none;" title="Español"><img src="https://otpokemon.com/images/flags/es.png" width="30px"/></a>' +
'<a href="#" class="lang-btn" data-lang="pl" style="text-decoration:none;" title="Polski"><img src="https://otpokemon.com/images/flags/pl.png" width="30px"/></a>' +
'</div>' +
'</nav>';
// Procura o menu "Navegação" e insere o de idiomas logo ACIMA dele
if ($('#p-navigation').length > 0) {
$('#p-navigation').before(menuHTML);
} else {
// Plano B de segurança, caso a página carregue de forma diferente
$('#mw-panel').prepend(menuHTML);
}
}
// 3. Lógica de tradução melhorada
$(document).on('click', '.lang-btn', function(e) {
e.preventDefault();
var targetLang = $(this).attr('data-lang');
var select = document.querySelector('.goog-te-combo');
// Se clicar em Português, forçamos a limpeza profunda dos cookies
if (targetLang === defaultLang) {
var host = location.hostname;
// Limpa o cookie na raiz
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
// Limpa o cookie no domínio exato
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=" + host + ";";
// Limpa o cookie com o prefixo de ponto (muito usado pelo Google)
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=." + host + ";";
// Se for um subdomínio (ex: wiki.otpokemon.com), limpa também o domínio principal (.otpokemon.com)
var parts = host.split('.');
if (parts.length > 2) {
var mainDomain = "." + parts[parts.length - 2] + "." + parts[parts.length - 1];
document.cookie = "googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=" + mainDomain + ";";
}
// Recarrega a página para aplicar a limpeza
location.reload();
return;
}
// Se clicar num idioma estrangeiro, chama o Google Translate
if (select) {
select.value = targetLang;
var event;
if (typeof Event === 'function') {
event = new Event('change');
} else {
event = document.createEvent('HTMLEvents');
event.initEvent('change', true, false);
}
select.dispatchEvent(event);
} else {
alert('O sistema de tradução ainda está a carregar. Por favor, aguarde um instante e tente novamente.');
}
});
});