|
1 | | -// CONTROLE DE TEMA |
2 | | -const themeButton = document.getElementById('theme-button'); |
3 | | -const storedTheme = localStorage.getItem('theme') || 'dark'; |
4 | | - |
5 | | -document.documentElement.setAttribute('data-theme', storedTheme); |
6 | | - |
7 | | -themeButton.addEventListener('click', () => { |
8 | | - let currentTheme = document.documentElement.getAttribute('data-theme'); |
9 | | - let newTheme = currentTheme === 'light' ? 'dark' : 'light'; |
10 | | - |
11 | | - document.documentElement.setAttribute('data-theme', newTheme); |
12 | | - localStorage.setItem('theme', newTheme); |
| 1 | +// TEMA CLARO/ESCURO |
| 2 | +const btn = document.getElementById('theme-button'); |
| 3 | +btn.addEventListener('click', () => { |
| 4 | + const doc = document.documentElement; |
| 5 | + const isLight = doc.getAttribute('data-theme') === 'light'; |
| 6 | + doc.setAttribute('data-theme', isLight ? 'dark' : 'light'); |
13 | 7 | }); |
14 | 8 |
|
15 | 9 | // SISTEMA DE PRÁTICAS |
16 | | -const aulasConteudo = { |
17 | | - 1: { titulo: "Variáveis", codigo: "let aluno = 'Bernardo';\nconsole.log('Bem-vindo, ' + aluno);" }, |
18 | | - 2: { titulo: "Funções", codigo: "function tchau(){ return 'Até logo!'; }\nconsole.log(tchau());" } |
| 10 | +const conteudo = { |
| 11 | + 1: { t: "Variáveis", c: "let nome = 'Bernardo';\nconsole.log('Olá, ' + nome);" }, |
| 12 | + 2: { t: "Funções", c: "function soma(a,b){ return a+b; }\nconsole.log(soma(5,10));" } |
19 | 13 | }; |
20 | 14 |
|
21 | 15 | function verAula(id) { |
22 | 16 | const area = document.getElementById('tutorial-texto'); |
23 | | - const aula = aulasConteudo[id]; |
24 | | - if(!area) return; |
25 | | - |
| 17 | + const aula = conteudo[id]; |
26 | 18 | area.innerHTML = ` |
27 | | - <div class="card" style="background: var(--bg-color); color: var(--text-color);"> |
28 | | - <h2 style="color: var(--accent)">Editando: ${aula.titulo}</h2> |
29 | | - <textarea id="codigo-editor">${aula.codigo}</textarea> |
30 | | - <button onclick="executar()" class="btn-primary">RODAR CÓDIGO</button> |
31 | | - <div id="console-output">> Resultado aparecerá aqui...</div> |
| 19 | + <div class="card" style="margin-bottom:20px;"> |
| 20 | + <h3>Praticando: ${aula.t}</h3> |
| 21 | + <textarea id="codigo-editor">${aula.c}</textarea> |
| 22 | + <button onclick="rodar()" class="btn-primary" style="margin-top:10px;">Executar</button> |
| 23 | + <div id="console-output">> Resultado...</div> |
32 | 24 | </div>`; |
33 | | - window.scrollTo({top: 0, behavior: 'smooth'}); |
34 | 25 | } |
35 | 26 |
|
36 | | -function executar() { |
37 | | - const cod = document.getElementById('codigo-editor').value; |
| 27 | +function rodar() { |
| 28 | + const code = document.getElementById('codigo-editor').value; |
38 | 29 | const out = document.getElementById('console-output'); |
39 | 30 | out.innerHTML = ""; |
40 | 31 | try { |
41 | | - const log = console.log; |
| 32 | + const originalLog = console.log; |
42 | 33 | console.log = (m) => { out.innerHTML += "> " + m + "<br>"; }; |
43 | | - eval(cod); |
44 | | - console.log = log; |
45 | | - } catch (e) { |
46 | | - out.innerHTML = "<span style='color:red;'>Erro: " + e.message + "</span>"; |
47 | | - } |
| 34 | + eval(code); |
| 35 | + console.log = originalLog; |
| 36 | + } catch(e) { out.innerHTML = "Erro: " + e.message; } |
48 | 37 | } |
0 commit comments