MediaWiki:Common.js

De otPokemon Wiki
Revisão de 16h17min de 5 de março de 2026 por Felipeaugusto (discussão | contribs) (Desfeita a edição 33697 de Felipeaugusto (Discussão))
Ir para navegação Ir para pesquisar

Nota: Após publicar, você pode ter que limpar o "cache" do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer/Edge: PressioneCtrl enquanto clica Recarregar, ou Pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
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 + ')');
        });
    });
});

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 ---
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 urlEN = mw.util.getUrl(basePageName + '/en') + '?uselang=en';
    var urlES = mw.util.getUrl(basePageName + '/es') + '?uselang=es';
    var urlPL = mw.util.getUrl(basePageName + '/pl') + '?uselang=pl';

    // Cria o HTML das bandeiras (agora com a Polónia)
    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="' + urlEN + '" style="font-size:28px; margin:0 5px; text-decoration:none;" title="English">🇺🇸</a>' +
        '<a href="' + urlES + '" style="font-size:28px; margin:0 5px; text-decoration:none;" title="Español">🇪🇸</a>' +
        '<a href="' + urlPL + '" style="font-size:28px; margin:0 5px; text-decoration:none;" title="Polski">🇵🇱</a>' +
        '</div>';

    // Injeta as bandeiras bem no topo da barra lateral
    $('#mw-panel').prepend(flags);
});