|
|
| (19 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) |
| Linha 1: |
Linha 1: |
| (function () {
| | // Sem JavaScript visual customizado. |
| function applyTheme(theme) {
| |
| document.documentElement.setAttribute('data-td-theme', theme);
| |
| localStorage.setItem('tdTheme', theme);
| |
| | |
| var btn = document.getElementById('td-theme-toggle');
| |
| if (btn) {
| |
| btn.textContent = theme === 'dark' ? '☀️ Modo claro' : '🌙 Modo escuro';
| |
| btn.setAttribute('aria-label', theme === 'dark' ? 'Ativar modo claro' : 'Ativar modo escuro');
| |
| }
| |
| }
| |
| | |
| function getInitialTheme() {
| |
| var saved = localStorage.getItem('tdTheme');
| |
| if (saved === 'dark' || saved === 'light') {
| |
| return saved;
| |
| }
| |
| | |
| if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
| |
| return 'dark';
| |
| }
| |
| | |
| return 'light';
| |
| }
| |
| | |
| function createButton() {
| |
| if (document.getElementById('td-theme-toggle')) {
| |
| return;
| |
| }
| |
| | |
| var btn = document.createElement('button');
| |
| btn.id = 'td-theme-toggle';
| |
| btn.type = 'button';
| |
| btn.onclick = function () {
| |
| var current = document.documentElement.getAttribute('data-td-theme') || 'light';
| |
| applyTheme(current === 'dark' ? 'light' : 'dark');
| |
| };
| |
| | |
| document.body.appendChild(btn);
| |
| applyTheme(document.documentElement.getAttribute('data-td-theme') || getInitialTheme());
| |
| }
| |
| | |
| applyTheme(getInitialTheme());
| |
| | |
| if (document.readyState === 'loading') {
| |
| document.addEventListener('DOMContentLoaded', createButton);
| |
| } else {
| |
| createButton();
| |
| }
| |
| })();
| |