Fait clignoter le favicon en rouge pendant un enregistrement

Favicon par défaut (static/favicon.svg) ; tant que /api/timer renvoie
une entrée en cours, il alterne chaque seconde entre un point rouge plein
et pâle, sur toutes les pages. État relu au chargement, après chaque
requête htmx, au retour sur l'onglet et toutes les 20 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Romulus21andClaude Opus 5.5 committed 2026-11-13 18:54:34 +01:00
1 parent aa4f5aeb0a
commit 0c9b9c5823
4 files changed
+47

No files matched your search

+41
View File
@@ -61,3 +61,44 @@ function removeRow(button) {
for (const input of row.querySelectorAll("input")) input._flatpickr?.destroy();
row.remove();
}
// Favicon : point rouge clignotant tant qu'un enregistrement est en cours,
// sur toutes les pages (état lu sur /api/timer).
const favicon = document.getElementById("favicon");
const IDLE_ICON = favicon.href;
const recIcon = (opacity) =>
"data:image/svg+xml," +
encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="13" fill="#e5322d" fill-opacity="${opacity}"/></svg>`,
);
const REC_ON = recIcon(1);
const REC_OFF = recIcon(0.2);
let recording = false;
let blinkOn = false;
function setRecording(value) {
if (value === recording) return;
recording = value;
blinkOn = true;
favicon.href = recording ? REC_ON : IDLE_ICON;
}
setInterval(() => {
if (!recording) return;
blinkOn = !blinkOn;
favicon.href = blinkOn ? REC_ON : REC_OFF;
}, 1000);
async function refreshRecording() {
try {
const res = await fetch("/api/timer", { headers: { accept: "application/json" } });
if (res.ok) setRecording((await res.json()) !== null);
} catch {
// Serveur injoignable : on garde l'état connu.
}
}
refreshRecording();
setInterval(refreshRecording, 20000);
document.addEventListener("visibilitychange", () => {
if (!document.hidden) refreshRecording();
});
document.body.addEventListener("htmx:afterRequest", refreshRecording);