EMYO_AI_ASISTANT / theme.js
fatmaTE's picture
Upload 3 files
edfdbc7 verified
Raw History Blame Contribute Delete
8.16 kB
(function() {
var DARK = {
'--bg-page': '#0f1117',
'--bg-main': '#161920',
'--bg-surface': '#1d2029',
'--bg-soft': '#252a36',
'--border-soft': '#323849',
'--user-bubble': '#252a36',
'--assistant-bubble': '#1d2029',
'--icon-blue': '#1a2840',
'--icon-blue-border': '#2b4470',
'--icon-blue-dark': '#7aabde',
'--accent': '#e0295e',
'--accent-2': '#4a8af4',
'--accent-soft': '#3d1527',
'--text-main': '#f1f5f9',
'--text-secondary': '#cbd5e1',
'--text-soft': '#94a3b8',
'--text-muted': '#64748b',
'--text-placeholder': '#475569',
'--text-on-accent': '#ffffff',
'--text-code': '#93c5fd',
'--text-link': '#60a5fa',
'--shadow-soft': '0 8px 24px rgba(0,0,0,0.35)',
'--shadow-accent': '0 8px 20px rgba(224,41,94,0.30)',
'--error-bg': '#2a1418',
'--error-border': '#7f1d1d',
'--error-border-left': '#ef4444',
'--error-text': '#fca5a5'
};
var LIGHT = {
'--bg-page': '#eef2f7',
'--bg-main': '#f7f9fc',
'--bg-surface': '#f4f7fb',
'--bg-soft': '#e8eef7',
'--border-soft': '#d8e0ec',
'--user-bubble': '#e4eaf3',
'--assistant-bubble': '#ffffff',
'--icon-blue': '#dbe8f8',
'--icon-blue-border': '#b8cde8',
'--icon-blue-dark': '#2b5f9e',
'--accent': '#a31747',
'--accent-2': '#0b4aa5',
'--accent-soft': '#f3d9e3',
'--text-main': '#111827',
'--text-secondary': '#4b5563',
'--text-soft': '#6b7280',
'--text-muted': '#9ca3af',
'--text-placeholder': '#adb5bd',
'--text-on-accent': '#ffffff',
'--text-code': '#1e3a5f',
'--text-link': '#0b4aa5',
'--shadow-soft': '0 8px 24px rgba(16,24,40,0.06)',
'--shadow-accent': '0 8px 20px rgba(163,23,71,0.18)',
'--error-bg': '#fff0f3',
'--error-border': '#f87171',
'--error-border-left': '#dc2626',
'--error-text': '#b91c1c'
};
function applyTheme(theme) {
var vars = theme === 'dark' ? DARK : LIGHT;
var root = document.documentElement;
for (var key in vars) root.style.setProperty(key, vars[key]);
root.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
var bg = vars['--bg-page'];
var bgMain = vars['--bg-main'];
var bgSurface = vars['--bg-surface'];
var text = vars['--text-main'];
var border = vars['--border-soft'];
[root, document.body].forEach(function(el) {
if (!el) return;
el.style.backgroundColor = bg;
el.style.color = text;
});
document.querySelectorAll(
'.gradio-container, .gradio-container .main, .gradio-container .wrap, .gradio-container > div'
).forEach(function(el) {
el.style.backgroundColor = bg;
el.style.color = text;
});
var header = document.getElementById('app-header');
if (header) {
header.style.backgroundColor = bgSurface;
header.style.borderColor = border;
header.style.color = text;
}
document.querySelectorAll('.header-title').forEach(function(el) { el.style.color = text; });
document.querySelectorAll('.header-subtitle').forEach(function(el) { el.style.color = vars['--text-soft']; });
var chatWin = document.getElementById('chat-window');
if (chatWin) {
chatWin.style.backgroundColor = bgMain;
chatWin.style.borderColor = border;
chatWin.style.color = text;
}
document.querySelectorAll(
'#chat-window .message, #chat-window .message-wrap, ' +
'#chat-window [data-testid="user"], #chat-window [data-testid="bot"]'
).forEach(function(el) {
el.style.color = text;
});
document.querySelectorAll(
'#chat-window .message *, #chat-window [data-testid="user"] *, #chat-window [data-testid="bot"] *'
).forEach(function(el) {
var tag = el.tagName ? el.tagName.toLowerCase() : '';
if (tag === 'code' || tag === 'pre') {
el.style.color = vars['--text-code'];
el.style.backgroundColor = vars['--bg-soft'];
} else if (tag === 'a') {
el.style.color = vars['--text-link'];
} else {
el.style.color = text;
}
});
document.querySelectorAll('#chat-window .message.user, #chat-window [data-testid="user"]').forEach(function(el) {
el.style.backgroundColor = vars['--user-bubble'];
el.style.borderColor = border;
});
document.querySelectorAll('#chat-window .message.bot, #chat-window [data-testid="bot"]').forEach(function(el) {
el.style.backgroundColor = vars['--assistant-bubble'];
});
document.querySelectorAll('#msg-box textarea').forEach(function(el) {
el.style.backgroundColor = bgSurface;
el.style.color = text;
el.style.borderColor = border;
});
document.querySelectorAll('#msg-box > div, #msg-box label, #msg-box .wrap').forEach(function(el) {
el.style.color = text;
});
var rBg = theme === 'dark' ? '#f4f7fb' : 'transparent';
var rBorder = theme === 'dark' ? '1.5px solid #cbd5e1' : '1.5px solid transparent';
var rFilter = 'none';
document.querySelectorAll('.header-logo').forEach(function(el) {
el.style.backgroundColor = rBg;
el.style.border = rBorder;
el.style.filter = rFilter;
});
document.querySelectorAll('.header-logo-fallback').forEach(function(el) {
el.style.backgroundColor = rBg;
el.style.border = rBorder;
el.style.color = vars['--accent'];
});
document.querySelectorAll('.header-icon').forEach(function(el) {
el.style.backgroundColor = 'transparent';
el.style.border = 'none';
el.style.boxShadow = 'none';
});
var btn = document.getElementById('theme-toggle');
if (btn) btn.innerHTML = theme === 'dark' ? '☀️' : '🌙';
}
var osDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
var isMobile = window.innerWidth < 768;
var saved;
if (isMobile) {
saved = osDark ? 'dark' : 'light';
} else {
saved = localStorage.getItem('theme') || (osDark ? 'dark' : 'light');
}
applyTheme(saved);
document.addEventListener('click', function(e) {
var el = e.target;
while (el) {
if (el.id === 'theme-toggle') {
var cur = document.documentElement.getAttribute('data-theme') || 'light';
applyTheme(cur === 'dark' ? 'light' : 'dark');
return;
}
el = el.parentElement;
}
});
var pending = false;
var observer = new MutationObserver(function() {
if (pending) return;
pending = true;
requestAnimationFrame(function() {
pending = false;
var theme = document.documentElement.getAttribute('data-theme') || 'light';
applyTheme(theme);
});
});
function startObserver() {
var target = document.getElementById('chat-window') || document.body;
if (target) observer.observe(target, { childList: true, subtree: true });
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', startObserver);
} else {
startObserver();
}
})();