|
|
| Linha 1: |
Linha 1: |
| var coll1 = document.getElementsByClassName("collapsible-battle-pass");
| | // --- SISTEMA DE BANDEIRAS, CACHE E REDIRECIONAMENTO --- |
| var coll2 = document.getElementsByClassName("collapsible-pokemon");
| | mw.loader.using(['mediawiki.util']).then(function() { |
| | | var pageName = mw.config.get('wgPageName'); |
| 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);
| |
| | | |
| | // 1. Identifica em qual idioma o jogador está agora (pela URL) |
| | var match = pageName.match(/\/(en|es|pl)$/); |
| | var urlLang = match ? match[1] : 'pt'; // Se não tem sufixo, assumimos PT |
| | var basePageName = pageName.replace(/\/(en|es|pl)$/, ''); |
|
| |
|
| $sortButton.on('click', function () { | | // 2. Lógica de Redirecionamento Automático |
| var $container = $('.square-div-shiny'); | | if (urlLang === 'pt') { // Só redireciona se ele tentar acessar a página raiz (em português) |
| var $boxes = $container.children('.square-box-shiny'); | | |
| | // Tenta pegar o idioma salvo. Se não tiver, pega o idioma nativo do Google Chrome/PC dele |
| | var prefLang = localStorage.getItem('otp_lang'); |
| | if (!prefLang) { |
| | var browserLang = navigator.language || navigator.userLanguage; |
| | if (browserLang.startsWith('en')) prefLang = 'en'; |
| | else if (browserLang.startsWith('es')) prefLang = 'es'; |
| | else if (browserLang.startsWith('pl')) prefLang = 'pl'; |
| | } |
|
| |
|
| $boxes.sort(function (a, b) {
| | // Se a preferência dele for estrangeira, manda ele pra página traduzida instantaneamente! |
| var numA = parseInt($(a).find('.square-name-shiny').text().match(/\d+/)[0], 10);
| | if (prefLang && ['en', 'es', 'pl'].includes(prefLang)) { |
| var numB = parseInt($(b).find('.square-name-shiny').text().match(/\d+/)[0], 10);
| | var redirectUrl = mw.util.getUrl(basePageName + '/' + prefLang) + '?uselang=' + prefLang; |
| | | window.location.replace(redirectUrl); |
| return isAscending ? numA - numB : numB - numA;
| | return; // Para o script aqui para não carregar mais nada |
| });
| | } |
| | |
| $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 + ')');
| |
| }); | |
| });
| |
| });
| |
| | |
| mw.hook('wikipage.content').add(function($content) {
| |
| // Detecta se a página atual é /en ou se o idioma da interface do usuário está em inglês
| |
| var isEnglish = mw.config.get('wgUserLanguage') === 'en' || mw.config.get('wgPageName').endsWith('/en');
| |
| var isSpannish = mw.config.get('wgUserLanguage') === 'es' || mw.config.get('wgPageName').endsWith('/es');
| |
| var isPolish = mw.config.get('wgUserLanguage') === 'pl' || mw.config.get('wgPageName').endsWith('/pl');
| |
|
| |
| if (isEnglish) {
| |
| // Pega todos os links da área de conteúdo
| |
| $content.find('a').each(function() {
| |
| var href = $(this).attr('href');
| |
|
| |
| // Só altera se for um link interno válido (começa com /, mas não com // que seria link externo)
| |
| if (href && href.startsWith('/') && !href.startsWith('//') && !href.includes('Special:') && !href.includes('Especial:') && !href.includes('?')) {
| |
|
| |
| // Evita colocar /en repetido
| |
| if (!href.endsWith('/en') && !href.includes('/en#')) {
| |
|
| |
| // Se o link tiver uma âncora (ex: /Charizard#Ataques), coloca o /en antes do #
| |
| if (href.includes('#')) {
| |
| $(this).attr('href', href.replace('#', '/en#'));
| |
| } else {
| |
| // Link normal
| |
| $(this).attr('href', href + '/en');
| |
| }
| |
| }
| |
| }
| |
| });
| |
| }
| |
| if (isSpannish) {
| |
| // Pega todos os links da área de conteúdo
| |
| $content.find('a').each(function() {
| |
| var href = $(this).attr('href'); | |
|
| |
| // Só altera se for um link interno válido (começa com /, mas não com // que seria link externo)
| |
| if (href && href.startsWith('/') && !href.startsWith('//') && !href.includes('Special:') && !href.includes('Especial:') && !href.includes('?')) {
| |
|
| |
| // Evita colocar /es repetido
| |
| if (!href.endsWith('/es') && !href.includes('/es#')) {
| |
|
| |
| // Se o link tiver uma âncora (ex: /Charizard#Ataques), coloca o /en antes do #
| |
| if (href.includes('#')) {
| |
| $(this).attr('href', href.replace('#', '/es#'));
| |
| } else {
| |
| // Link normal
| |
| $(this).attr('href', href + '/es');
| |
| }
| |
| }
| |
| }
| |
| }); | |
| } | | } |
| if (isPolish) {
| |
| // Pega todos os links da área de conteúdo
| |
| $content.find('a').each(function() {
| |
| var href = $(this).attr('href');
| |
|
| |
| // Só altera se for um link interno válido (começa com /, mas não com // que seria link externo)
| |
| if (href && href.startsWith('/') && !href.startsWith('//') && !href.includes('Special:') && !href.includes('Especial:') && !href.includes('?')) {
| |
|
| |
| if (!href.endsWith('/pl') && !href.includes('/pl#')) {
| |
|
| |
| // Se o link tiver uma âncora (ex: /Charizard#Ataques), coloca o /en antes do #
| |
| if (href.includes('#')) {
| |
| $(this).attr('href', href.replace('#', '/pl#'));
| |
| } else {
| |
| // Link normal
| |
| $(this).attr('href', href + '/pl');
| |
| }
| |
| }
| |
| }
| |
| });
| |
| }
| |
| });
| |
|
| |
|
| // --- SISTEMA DE BANDEIRAS DE IDIOMA ---
| | // 3. Monta as URLs para as bandeiras |
| mw.loader.using(['mediawiki.util']).then(function() {
| |
| var pageName = mw.config.get('wgPageName'); | |
|
| |
| // Remove o /en, /es ou /pl do nome da página atual para saber qual é a página "base"
| |
| var basePageName = pageName.replace(/\/(en|es|pl)$/, '');
| |
| | |
| // Monta os links usando a URL correta da sua wiki e força a tradução da interface (?uselang=)
| |
| var urlPT = mw.util.getUrl(basePageName) + '?uselang=pt-br'; | | var urlPT = mw.util.getUrl(basePageName) + '?uselang=pt-br'; |
| var urlEN = mw.util.getUrl(basePageName + '/en') + '?uselang=en'; | | var urlEN = mw.util.getUrl(basePageName + '/en') + '?uselang=en'; |
| Linha 197: |
Linha 34: |
| var urlPL = mw.util.getUrl(basePageName + '/pl') + '?uselang=pl'; | | var urlPL = mw.util.getUrl(basePageName + '/pl') + '?uselang=pl'; |
|
| |
|
| // Cria o HTML das bandeiras (agora com a Polónia) | | // Cria o HTML adicionando um "ID" para cada bandeira |
| var flags = '<div id="wiki-flags" style="text-align:center; padding:15px 0 5px 0; margin-bottom:10px;">' + | | var flags = '<div id="wiki-flags" style="text-align:center; padding:15px 0 5px 0; margin-bottom:10px;">' + |
| '<a href="' + urlPT + '" style="font-size:28px; margin:0 5px; text-decoration:none;" title="Português">🇧🇷</a>' + | | '<a href="' + urlPT + '" id="flag-pt" style="font-size:26px; margin:0 4px; text-decoration:none; display:inline-block; padding:3px;" title="Português">🇧🇷</a>' + |
| '<a href="' + urlEN + '" style="font-size:28px; margin:0 5px; text-decoration:none;" title="English">🇺🇸</a>' + | | '<a href="' + urlEN + '" id="flag-en" style="font-size:26px; margin:0 4px; text-decoration:none; display:inline-block; padding:3px;" title="English">🇺🇸</a>' + |
| '<a href="' + urlES + '" style="font-size:28px; margin:0 5px; text-decoration:none;" title="Español">🇪🇸</a>' + | | '<a href="' + urlES + '" id="flag-es" style="font-size:26px; margin:0 4px; text-decoration:none; display:inline-block; padding:3px;" title="Español">🇪🇸</a>' + |
| '<a href="' + urlPL + '" style="font-size:28px; margin:0 5px; text-decoration:none;" title="Polski">🇵🇱</a>' + | | '<a href="' + urlPL + '" id="flag-pl" style="font-size:26px; margin:0 4px; text-decoration:none; display:inline-block; padding:3px;" title="Polski">🇵🇱</a>' + |
| '</div>'; | | '</div>'; |
|
| |
|
| // Injeta as bandeiras bem no topo da barra lateral | | // Injeta as bandeiras na barra lateral |
| $('#mw-panel').prepend(flags); | | $('#p-navigation').before(flags); |
| | |
| | // 4. Aplica a classe CSS (borda/brilho) na bandeira do idioma atual |
| | $('#flag-' + urlLang).addClass('flag-ativa'); |
| | |
| | // 5. Salva a escolha no PC do jogador quando ele clica em uma bandeira |
| | $('#wiki-flags a').on('click', function() { |
| | var clickedLang = $(this).attr('id').replace('flag-', ''); |
| | localStorage.setItem('otp_lang', clickedLang); |
| | }); |
| }); | | }); |