atualizacoes

This commit is contained in:
2026-06-25 12:30:47 +00:00
parent bb80be896f
commit 1ddf9b7def
21 changed files with 679 additions and 180 deletions
+7 -18
View File
@@ -1,22 +1,14 @@
// 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 (getInitialTheme()) {
document.documentElement.classList.add('dark-mode-pending');
}
function applyTheme(enable, isManual) {
document.documentElement.classList.remove('dark-mode-pending');
if (document.body) {
document.body.classList.toggle('dark-mode', enable);
}
@@ -31,7 +23,7 @@
window.darkModeToggle = function() {
var isDark = localStorage.getItem('chatc2_dark_mode') === 'true';
applyTheme(!isDark, true); // toggle manual
applyTheme(!isDark, true);
};
window.darkModeApply = function(enable) { applyTheme(enable, false); };
@@ -40,19 +32,16 @@
return localStorage.getItem('chatc2_dark_mode') === 'true';
};
// Reage a mudanças no tema do sistema (só quando não há override manual)
// Reage a mudanças no SO (só sem 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(getInitialTheme(), false);
});
} else {
applyTheme(getInitialTheme(), false);
}
// Aplica imediatamente (sem esperar DOMContentLoaded)
// Sincroniza html.dark (setado pelo script inline no <head>) com body.dark-mode
var htmlDark = document.documentElement.classList.contains('dark');
applyTheme(htmlDark || getInitialTheme(), false);
document.documentElement.classList.remove('dark');
})();