alterações de melhorias

This commit is contained in:
2026-06-24 14:13:09 +00:00
parent d942694ec0
commit 29190cd71c
34 changed files with 2570 additions and 950 deletions
+30 -8
View File
@@ -1,14 +1,29 @@
// Dark Mode Controller — Unified for all Chatc2 pages
(function() {
// Detecta preferência do sistema
var osPrefersDark = window.matchMedia('(prefers-color-scheme: dark)');
var manualOverride = localStorage.getItem('chatc2_dark_mode_manual');
// Decide tema inicial: manual > preferência OS > claro
function getInitialTheme() {
if (manualOverride !== null) return manualOverride === 'true';
return osPrefersDark.matches;
}
// Apply on load immediately (FOUC prevention)
if (localStorage.getItem('chatc2_dark_mode') === 'true') {
if (getInitialTheme()) {
document.documentElement.classList.add('dark-mode-pending');
}
function applyTheme(enable) {
function applyTheme(enable, isManual) {
document.documentElement.classList.remove('dark-mode-pending');
document.body && document.body.classList.toggle('dark-mode', enable);
if (document.body) {
document.body.classList.toggle('dark-mode', enable);
}
localStorage.setItem('chatc2_dark_mode', enable ? 'true' : 'false');
if (isManual) {
localStorage.setItem('chatc2_dark_mode_manual', enable ? 'true' : 'false');
}
document.querySelectorAll('.dark-mode-toggle').forEach(function(btn) {
btn.innerHTML = enable ? '☀️ Claro' : '🌙 Escuro';
});
@@ -16,21 +31,28 @@
window.darkModeToggle = function() {
var isDark = localStorage.getItem('chatc2_dark_mode') === 'true';
applyTheme(!isDark);
applyTheme(!isDark, true); // toggle manual
};
window.darkModeApply = function(enable) { applyTheme(enable); };
window.darkModeApply = function(enable) { applyTheme(enable, false); };
window.darkModeIsDark = function() {
return localStorage.getItem('chatc2_dark_mode') === 'true';
};
// Apply stored preference after DOM ready
// Reage a mudanças no tema do sistema (só quando não há override manual)
osPrefersDark.addEventListener('change', function(e) {
if (localStorage.getItem('chatc2_dark_mode_manual') === null) {
applyTheme(e.matches, false);
}
});
// Apply after DOM ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
applyTheme(localStorage.getItem('chatc2_dark_mode') === 'true');
applyTheme(getInitialTheme(), false);
});
} else {
applyTheme(localStorage.getItem('chatc2_dark_mode') === 'true');
applyTheme(getInitialTheme(), false);
}
})();