Skip to content

Commit

Permalink
Melhoria na dinâmica do código do modo escuro
Browse files Browse the repository at this point in the history
  • Loading branch information
filhodepeterpan committed Sep 3, 2024
1 parent a17d3dd commit af140b1
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions scripts/modo.escuro.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,30 @@ function ativaModoEscuro() {
const iconePerfilEscuro = document.getElementById("foto__de__perfil__escuro");
const botaoTexto = document.querySelector("button #text");

if (!modoEscuro){
document.documentElement.style.setProperty('--cor-bg', '#121212');
document.documentElement.style.setProperty('--cor-constrate-bg', '#1d1d1d');
document.documentElement.style.setProperty('--cor-fonte-cinza', '#e0e0e0');
document.documentElement.style.setProperty('--cor-destaque', '#d437ff');
document.documentElement.style.setProperty('--cor-destaque-light', '#bb86fc');
document.documentElement.style.setProperty('--cor-urgente', '#dc3546');
document.documentElement.style.setProperty('--cor-critica', '#ff8c00');
document.documentElement.style.setProperty('--cor-atencao', '#ffd600');
document.documentElement.style.setProperty('--cor-ok', '#03dac6');
document.documentElement.style.setProperty('--cor-fonte', '#ffffff')

botaoTexto.textContent = "Desativar Modo Escuro";
iconePerfilPadrao.style.display = "none";
iconePerfilEscuro.style.display = "inline";
}
else{
document.documentElement.style.removeProperty('--cor-bg');
document.documentElement.style.removeProperty('--cor-constrate-bg');
document.documentElement.style.removeProperty('--cor-fonte-cinza');
document.documentElement.style.removeProperty('--cor-destaque');
document.documentElement.style.removeProperty('--cor-destaque-light');
document.documentElement.style.removeProperty('--cor-urgente');
document.documentElement.style.removeProperty('--cor-critica');
document.documentElement.style.removeProperty('--cor-atencao');
document.documentElement.style.removeProperty('--cor-ok');
document.documentElement.style.removeProperty('--cor-fonte');

botaoTexto.textContent = "Ativar Modo Escuro";
iconePerfilPadrao.style.display = "inline";
iconePerfilEscuro.style.display = "none";
const root = {
'--cor-bg': '#121212',
'--cor-constrate-bg': '#1d1d1d',
'--cor-fonte-cinza': '#e0e0e0',
'--cor-destaque': '#d437ff',
'--cor-destaque-light': '#bb86fc',
'--cor-urgente': '#dc3546',
'--cor-critica': '#ff8c00',
'--cor-atencao': '#ffd600',
'--cor-ok': '#03dac6',
'--cor-fonte': '#ffffff'
};

for (const [variavel, cor] of Object.entries(root)) {
if (!modoEscuro) {
document.documentElement.style.setProperty(variavel, cor);
} else {
document.documentElement.style.removeProperty(variavel);
}
}

botaoTexto.textContent = modoEscuro ? "Ativar Modo Escuro" : "Desativar Modo Escuro";
iconePerfilPadrao.style.display = modoEscuro ? "inline" : "none";
iconePerfilEscuro.style.display = modoEscuro ? "none" : "inline";

modoEscuro = !modoEscuro;
}

0 comments on commit af140b1

Please sign in to comment.