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
 
(Uma revisão intermediária pelo mesmo usuário não está sendo mostrada)
Linha 1: Linha 1:
/* ===== CARREGAMENTO ===== */
/* Carregar preferência */  
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", function () { const saved = localStorage.getItem("theme");


    /* Remover link das imagens */
if (saved === "dark")  
    document.querySelectorAll('a.image').forEach(function(el) {
{ document.body.classList.add("dark-mode");  
        el.removeAttribute('href');
} else {  
    });
document.body.classList.add("light-mode");  
 
}  
    /* Carregar tema salvo */
    const saved = localStorage.getItem("theme");
 
    if (saved === "dark") {
        document.body.classList.add("dark-mode");
    } else {
        document.body.classList.add("light-mode");
    }
 
    /* Criar botão flutuante */
    const btn = document.createElement("button");
    btn.innerHTML = "🌙";
    btn.id = "theme-toggle-btn";
 
    btn.onclick = function () {
        toggleTheme();
 
        // trocar ícone
        if (document.body.classList.contains("dark-mode")) {
            btn.innerHTML = "🌙";
        } else {
            btn.innerHTML = "☀️";
        }
    };
 
    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 atual tal como às 16h49min de 2 de maio de 2026

/* Carregar preferência */ 
document.addEventListener("DOMContentLoaded", function () { const saved = localStorage.getItem("theme"); 

if (saved === "dark") 
{ document.body.classList.add("dark-mode"); 
} else { 
document.body.classList.add("light-mode"); 
} 
});