From 9e784c8b8b881127010ae8f46ad3123cd30d1a20 Mon Sep 17 00:00:00 2001 From: tyler Date: Tue, 19 May 2026 02:07:25 -0400 Subject: [PATCH] Attempting to make elements theme aware --- ollama_answers.py | 58 +++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/ollama_answers.py b/ollama_answers.py index d38e940..19c65cf 100644 --- a/ollama_answers.py +++ b/ollama_answers.py @@ -344,7 +344,7 @@ INTERACTIVE_CSS = ''' appearance: none; -webkit-appearance: none; background: url("data:image/svg+xml;charset=UTF-8,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20512%20512%22%3E%0A%3Cg%20fill%3D%22%23aaa%22%3E%0A%3Cpolygon%20points%3D%22128%2C192%20256%2C320%20384%2C192%22%2F%3E%3C%2Fg%3E%0A%3C%2Fsvg%3E") calc(100% + 2rem) / 1rem no-repeat content-box border-box; - background-color: #424247; + background-color: var(--color-toolkit-select-background, #424247); text-overflow: ellipsis; border-width: 0 2rem 0 0; border-color: transparent; @@ -361,7 +361,7 @@ INTERACTIVE_CSS = ''' vertical-align: middle; } .sxng-model-select:hover { - background-color: #303033; + background-color: var(--color-result-hover, #303033); color: var(--color-search-url, #bbb); } .sxng-reasoning { @@ -600,23 +600,6 @@ INTERACTIVE_JS = r''' _ms.appendChild(_o); } } - if (window.getComputedStyle && box) { - try { - const docStyles = getComputedStyle(document.documentElement); - let accent = docStyles.getPropertyValue('--color-result-link').trim(); - if (!accent) { - const a = document.createElement('a'); - document.body.appendChild(a); - accent = getComputedStyle(a).color; - document.body.removeChild(a); - } - if (accent) { - box.style.setProperty('--color-result-link', accent); - box.style.setProperty('--sxng-ai-accent', accent); - } - } catch(e) {} - } - // conversation saved as base64 URL fragment. const updateState = () => { try { @@ -877,6 +860,41 @@ FRONTEND_JS_TEMPLATE = r""" const box = document.getElementById('sxng-stream-box'); const data = document.getElementById('sxng-stream-data'); + (function applyTheme() { + try { + const root = document.documentElement; + const s = getComputedStyle(root); + const get = (v, fallback) => s.getPropertyValue(v).trim() || fallback; + + const theme = { + '--color-answer-background': get('--color-answer-background', '#313338'), + '--color-answer-font': get('--color-answer-font', '#fff'), + '--color-result-link': get('--color-result-link', '#8aacf7'), + '--color-base-font': get('--color-base-font', '#cdd6f4'), + '--color-sidebar-bg': get('--color-sidebar-bg', '#424247'), + '--color-result-hover': get('--color-result-hover', '#303033'), + '--color-base-background': get('--color-base-background', '#2a2a2e'), + '--color-search-font': get('--color-search-font', '#bbb'), + '--color-result-border': get('--color-result-border', '#4c566a'), + '--color-result-description':get('--color-result-description', '#d8dee9'), + '--color-toolkit-select-background': get('--color-toolkit-select-background', '#313338'), + }; + + // Apply to box and any ai-answers container + const targets = [box, document.getElementById('ai-answers')].filter(Boolean); + targets.forEach(el => { + Object.entries(theme).forEach(([k, v]) => { + if (v) el.style.setProperty(k, v); + }); + }); + + // Also apply to document root so our CSS vars cascade + Object.entries(theme).forEach(([k, v]) => { + if (v) box.style.setProperty(k, v); + }); + } catch(e) {} + })(); + // Move AI Overview outside #answers, place it before #results (function relocateBox() { const answersDiv = document.getElementById('answers'); @@ -2112,7 +2130,7 @@ class SXNGPlugin(Plugin):
- AI Overview + AI Overview