Browse Source

status-indicator-ready-and-stopped-colors

master
Serge Shutov 1 week ago
parent
commit
13d68abd3d
  1. 6
      content/content.js
  2. 2
      content/overlay.css
  3. 2
      content/panel.js

6
content/content.js

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
UI.onStop(function () { queue.length = 0; started = false; try { obs.disconnect(); } catch (e) {} if (UI) { UI.setPhase('off'); UI.setStartEnabled(true); if (UI.setDot) UI.setDot('stopped'); UI.log('stopped'); } });
UI.onSaveToken(function (v) { chrome.storage.local.set({ 'dshmem-bridge-token': v }, function () { if (UI) UI.log('token saved, reload page'); }); });
}
if (UI) { UI.onStart(function () { if (!canStart) { if (UI.setStartEnabled) UI.setStartEnabled(true); return; } started = true; markExistingAsProcessed(); obs.observe(document.documentElement, { childList: true, subtree: true, characterData: true }); UI.setPhase('idle'); UI.setConnected(true); UI.log('started'); }); }
if (UI) { UI.onStart(function () { if (!canStart) { if (UI.setStartEnabled) UI.setStartEnabled(true); return; } started = true; markExistingAsProcessed(); obs.observe(document.documentElement, { childList: true, subtree: true, characterData: true }); UI.setPhase('idle'); UI.setConnected(true); if (UI.setDot) UI.setDot('ok'); UI.log('started'); }); }
window.addEventListener('dshmem:metrics', function (e) { try { var mm = JSON.parse(e.detail); if (UI && UI.setMetrics) UI.setMetrics(mm); } catch (err) {} }); if (!SEL) return;
if (!BRIDGE) return;
if (typeof extractCalls !== "function") return;
@ -359,7 +359,7 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text @@ -359,7 +359,7 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text
UI.setPhase('off');
UI.setConnected(!!(r && r.ok));
if (!r || !r.ok) UI.log('bridge down: ' + ((r && r.error && r.error.message) || '?'));
else UI.log('ready, press Start');
else { if (UI.setDot) UI.setDot('ok'); UI.log('ready, press Start'); }
}
canStart = true;
}).catch(function (e) {
@ -367,7 +367,7 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text @@ -367,7 +367,7 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text
canStart = true;
});
setInterval(function () {
BRIDGE.health().then(function (r) { if (UI && UI.setConnected) UI.setConnected(!!(r && r.ok)); });
BRIDGE.health().then(function (r) { if (UI && UI.setConnected) { UI.setConnected(!!(r && r.ok)); if (r && r.ok && UI.setDot) UI.setDot('ok'); } });
}, 30000);
__refreshStats();
});

2
content/overlay.css

@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
.dshmem-dot.err { background: #ff5f57; }
.dshmem-dot.busy { background: #ffcc00; animation: dshmem-blink 1s infinite; } .dshmem-dot.ok-busy { background: #34c759; animation: dshmem-blink 1s infinite; }
.dshmem-dot.off { background: #666; }
.dshmem-dot.stopped { background: #666; }
.dshmem-dot.stopped { background: #ff9500; }
.dshmem-dot.error { background: #ff5f57; animation: dshmem-blink 1s infinite; }
@keyframes dshmem-blink { 50% { opacity: 0.35; } }

2
content/panel.js

@ -75,7 +75,7 @@ @@ -75,7 +75,7 @@
}
var API = {
setPhase: function (p) { state.phase = p; if (el.phase) el.phase.textContent = p; },
setConnected: function (b) { state.connected = !!b; API._applyDot(); }, setDot: function (m) { state.dotMode = m || null; API._applyDot(); }, _applyDot: function () { if (!el.dot) return; var cls = 'dshmem-dot'; if (!state.connected) { cls += ' err'; } else { var m = state.dotMode || 'off'; if (m === 'busy' || m === 'ok-busy') cls += ' busy'; else if (m === 'error') cls += ' error'; else if (m === 'stopped') cls += ' stopped'; else if (m === 'ok') cls += ' ok'; else cls += ' off'; } el.dot.className = cls; },
setConnected: function (b) { state.connected = !!b; API._applyDot(); }, setDot: function (m) { state.dotMode = m || null; API._applyDot(); }, _applyDot: function () { if (!el.dot) return; var cls = 'dshmem-dot'; if (!state.connected) { cls += ' err'; } else { var m = state.dotMode || 'ok'; if (m === 'busy' || m === 'ok-busy') cls += ' busy'; else if (m === 'error') cls += ' error'; else if (m === 'stopped') cls += ' stopped'; else if (m === 'ok') cls += ' ok'; else cls += ' off'; } el.dot.className = cls; },
setStartEnabled: function (b) { if (el.start) el.start.disabled = !b; }, setStats: function (ws, memN, skillN) { if (!el.stats) return; el.stats.textContent = 'WS: ' + (ws || '?') + ' mem: ' + (memN || 0) + ' skills: ' + (skillN || 0); }, setMetrics: function (m) { if (!el.metrics) return; if (!m) { el.metrics.textContent = 'metrics: —'; return; } state.lastMetrics = m; var __pct = 0; if (state.accLimit > 0) __pct = Math.round((m.accum || 0) * 100 / state.accLimit); var __cls = 'dshmem-acc-ok'; if (__pct > 100) __cls = 'dshmem-acc-crit'; else if (__pct >= 80) __cls = 'dshmem-acc-err'; else if (__pct >= 40) __cls = 'dshmem-acc-warn'; el.metrics.className = 'dshmem-stats ' + __cls; el.metrics.textContent = 'acc: ' + m.accum + ' · turn: ' + m.delta + ' · msg: ' + m.chars + 'ch (~' + m.est_tok + 't) ctx ' + (m.ctx_tok || 0) + 't ' + (m.ctx_pct || 0) + 'pct'; },
toggleForceInject: function () {
state.forceInject = !state.forceInject;

Loading…
Cancel
Save