MediaWiki:Common.js: mudanças entre as edições

De Wiki PokeLegends
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
Linha 1: Linha 1:
/* ===== CARREGAMENTO ===== */
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", function () {


     /* Remover link das imagens */
     /* Remover link das imagens */
     document.querySelectorAll('a.image').forEach(function(el) {
     document.querySelectorAll('a.image').forEach(el => el.removeAttribute('href'));
        el.removeAttribute('href');
    });


    /* Carregar tema salvo */
     const saved = localStorage.getItem("theme");
     const saved = localStorage.getItem("theme");
    document.body.classList.add(saved === "light" ? "light-mode" : "dark-mode");


     if (saved === "dark") {
     /* Criar botão */
        document.body.classList.add("dark-mode");
    const btn = document.createElement("button");
     } else {
    btn.id = "theme-toggle-btn";
         document.body.classList.add("light-mode");
 
     function updateIcon() {
         btn.innerHTML = document.body.classList.contains("dark-mode") ? "🌙" : "☀️";
     }
     }


     /* Criar botão flutuante */
     updateIcon();
    const btn = document.createElement("button");
    btn.innerHTML = "🌙";
    btn.id = "theme-toggle-btn";


     btn.onclick = function () {
     btn.onclick = function () {
         toggleTheme();
         document.body.classList.toggle("dark-mode");
        document.body.classList.toggle("light-mode");
 
        const current = document.body.classList.contains("dark-mode") ? "dark" : "light";
        localStorage.setItem("theme", current);


         // trocar ícone
         updateIcon();
        if (document.body.classList.contains("dark-mode")) {
            btn.innerHTML = "🌙";
        } else {
            btn.innerHTML = "☀️";
        }
     };
     };


     document.body.appendChild(btn);
     document.body.appendChild(btn);
});
});
/* ===== TROCA DE TEMA ===== */
function toggleTheme() {
    const body = document.body;
    if (body.classList.contains("dark-mode")) {
        body.classList.remove("dark-mode");
        body.classList.add("light-mode");
        localStorage.setItem("theme", "light");
    } else {
        body.classList.remove("light-mode");
        body.classList.add("dark-mode");
        localStorage.setItem("theme", "dark");
    }
}

Edição das 16h43min de 2 de maio de 2026

document.addEventListener("DOMContentLoaded", function () {

    /* Remover link das imagens */
    document.querySelectorAll('a.image').forEach(el => el.removeAttribute('href'));

    const saved = localStorage.getItem("theme");
    document.body.classList.add(saved === "light" ? "light-mode" : "dark-mode");

    /* Criar botão */
    const btn = document.createElement("button");
    btn.id = "theme-toggle-btn";

    function updateIcon() {
        btn.innerHTML = document.body.classList.contains("dark-mode") ? "🌙" : "☀️";
    }

    updateIcon();

    btn.onclick = function () {
        document.body.classList.toggle("dark-mode");
        document.body.classList.toggle("light-mode");

        const current = document.body.classList.contains("dark-mode") ? "dark" : "light";
        localStorage.setItem("theme", current);

        updateIcon();
    };

    document.body.appendChild(btn);
});