/
an_cheser
/
FlexTime
Обзор
Документация
Войти
/
an_cheser
/
FlexTime
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
timer.js
79 строк
3 KB
an_cheser
Объединение записей в карточки временных пар
05 июн 2026, 17:19
Верифицирован
05 июн 2026, 17:19
02b20b1
Код
Авторство
О чём код?
// ========== Живой таймер ========== let liveTimerInterval = null; let liveStartTime = null; let progressInterval = null; let activeDurationsInterval = null; function stopLiveTimer() { if (liveTimerInterval) { clearInterval(liveTimerInterval); liveTimerInterval = null; } liveStartTime = null; const timerEl = document.getElementById('liveTimer'); if (timerEl) timerEl.style.display = 'none'; const leaveBtn = document.getElementById('leaveBtn'); if (leaveBtn) leaveBtn.classList.remove('active-timer'); } function updateTimerDisplay() { if (!liveStartTime) return; const diff = Math.max(0, Date.now() - liveStartTime); const h = Math.floor(diff / 3600000); const m = Math.floor((diff % 3600000) / 60000); const s = Math.floor((diff % 60000) / 1000); const display = `⏳ ${String(h).padStart(2,'0')}:${String(m).padStart(2,'0')}:${String(s).padStart(2,'0')}`; const el = document.getElementById('liveTimer'); if (el) el.textContent = display; } function resumeLiveTimer() { const sorted = [...history].sort((a, b) => (a.timestamp || 0) - (b.timestamp || 0)); let lastArrive = null; for (const r of sorted) { if (r.type === 'arrive') lastArrive = r; else if (r.type === 'leave') lastArrive = null; } if (lastArrive && lastArrive.timestamp <= Date.now()) { liveStartTime = lastArrive.timestamp; if (liveTimerInterval) return; updateTimerDisplay(); liveTimerInterval = setInterval(updateTimerDisplay, 1000); const timerEl = document.getElementById('liveTimer'); if (timerEl) timerEl.style.display = 'block'; const leaveBtn = document.getElementById('leaveBtn'); if (leaveBtn) leaveBtn.classList.add('active-timer'); } else { stopLiveTimer(); } } function getLastEntryType() { const sorted = [...history].sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0)); return sorted.length > 0 ? sorted[0].type : null; } function getLastWorkEntryType() { const sorted = [...history].sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0)); for (const r of sorted) { if (r.type === 'work_start') return 'work_start'; if (r.type === 'work_end') return 'work_end'; if (r.type === 'arrive') return 'work_start'; if (r.type === 'leave') return 'work_end'; } return null; } function startProgressUpdater() { if (progressInterval) return; // уже запущен // Обновляем прогресс раз в 60 секунд progressInterval = setInterval(updateProgressBar, 60000); } function stopProgressUpdater() { if (progressInterval) { clearInterval(progressInterval); progressInterval = null; } }