Files
2026-10-14 19:29:31 +02:00

26 lines
643 B
JavaScript

const FPS = 25;
function pad(n) {
return String(n).padStart(2, "0");
}
export function initTimecode(el) {
const start = performance.now();
const tick = (now) => {
if (!el.isConnected) {
return;
}
const frames = Math.floor(((now - start) / 1000) * FPS);
const f = frames % FPS;
const s = Math.floor(frames / FPS) % 60;
const m = Math.floor(frames / (FPS * 60)) % 60;
const h = Math.floor(frames / (FPS * 3600));
el.textContent = `${pad(h)}:${pad(m)}:${pad(s)}:${pad(f)}`;
requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
}