V1
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/* Icônes de statut : compatible avec alfred.js existant, sans le remplacer. */
|
||||
(() => {
|
||||
'use strict';
|
||||
const el = document.getElementById('mode');
|
||||
if (!el) return;
|
||||
const icons = {
|
||||
idle: ['🛏️', 'Repos'], repos: ['🛏️', 'Repos'],
|
||||
listening: ['👂', 'Écoute'], thinking: ['🧠', 'Réflexion'],
|
||||
speaking: ['🔊', 'Parole'], error: ['⚠️', 'Erreur']
|
||||
};
|
||||
let current = 'idle';
|
||||
function apply(raw) {
|
||||
const key = String(raw || '').trim().toLowerCase();
|
||||
if (!icons[key]) return;
|
||||
current = key;
|
||||
const [icon, label] = icons[key];
|
||||
if (el.textContent !== icon) el.textContent = icon;
|
||||
el.title = label;
|
||||
el.setAttribute('aria-label', label);
|
||||
el.dataset.mode = key;
|
||||
}
|
||||
// L'ancien alfred.js écrit le nom du mode dans #mode.
|
||||
// L'observateur le convertit immédiatement en icône, sans modifier ce script.
|
||||
const observer = new MutationObserver(() => {
|
||||
const value = el.textContent.trim();
|
||||
if (icons[value.toLowerCase()]) apply(value);
|
||||
});
|
||||
observer.observe(el, { childList: true, characterData: true, subtree: true });
|
||||
apply(el.textContent);
|
||||
// Récupère également l'état actuel après un rafraîchissement de page.
|
||||
fetch('/api/state', { cache: 'no-store' })
|
||||
.then(r => { if (!r.ok) throw new Error('État indisponible'); return r.json(); })
|
||||
.then(data => { if (data && data.mode) apply(data.mode); })
|
||||
.catch(() => {});
|
||||
})();
|
||||
Reference in New Issue
Block a user