Repository navigation
Expand file tree
/
Copy pathtimer.js
More file actions
92 lines (80 loc) · 2.89 KB
/
Copy pathtimer.js
File metadata and controls
92 lines (80 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// js/timer.js
// Time limits matching V2 [Green, Yellow, Red] in seconds
const timeLimits = {
'table-topics': [60, 90, 120],
'evaluation': [120, 150, 180],
'ice-breaker': [240, 300, 360],
'standard': [300, 360, 420]
};
// DOM Elements
const speechTypeSelect = document.getElementById('guest-speech-type');
const timerDisplay = document.getElementById('guest-timer-display');
const btnToggle = document.getElementById('btn-guest-toggle');
const btnReset = document.getElementById('btn-guest-reset');
const guestContainer = document.getElementById('guest-timer-container');
// State
let seconds = 0;
let timerInterval = null;
let isRunning = false;
// Helper: Format seconds to MM:SS
function formatTime(totalSeconds) {
const m = Math.floor(totalSeconds / 60).toString().padStart(2, '0');
const s = (totalSeconds % 60).toString().padStart(2, '0');
return `${m}:${s}`;
}
// Logic: Update Colors based on Speech Type
function updateColors() {
const currentType = speechTypeSelect.value;
if (!currentType) return;
const [green, yellow, red] = timeLimits[currentType];
// Reset background
guestContainer.style.backgroundColor = 'var(--tm-white)';
timerDisplay.style.color = 'var(--tm-black)';
// Apply colors (matching V2 logic)
if (seconds >= red) {
guestContainer.style.backgroundColor = 'var(--tm-loyal-red)';
timerDisplay.style.color = 'var(--tm-white)';
} else if (seconds >= yellow) {
guestContainer.style.backgroundColor = 'var(--tm-happy-yellow)';
timerDisplay.style.color = 'var(--tm-black)';
} else if (seconds >= green) {
guestContainer.style.backgroundColor = '#10B981'; // Functional Green
timerDisplay.style.color = 'var(--tm-white)';
}
}
// Actions
btnToggle.addEventListener('click', () => {
if (!speechTypeSelect.value) {
alert("Please select a speech type first.");
return;
}
if (!isRunning) {
// Start Timer
isRunning = true;
btnToggle.textContent = "Stop";
btnToggle.style.backgroundColor = "var(--tm-loyal-red)";
btnReset.style.display = 'none';
timerInterval = setInterval(() => {
seconds++;
timerDisplay.textContent = formatTime(seconds);
updateColors();
}, 1000);
} else {
// Stop Timer
isRunning = false;
clearInterval(timerInterval);
btnToggle.textContent = "Resume";
btnToggle.style.backgroundColor = "var(--tm-true-blue)";
btnReset.style.display = 'block';
}
});
btnReset.addEventListener('click', () => {
isRunning = false;
clearInterval(timerInterval);
seconds = 0;
timerDisplay.textContent = "00:00";
guestContainer.style.backgroundColor = 'var(--tm-white)';
timerDisplay.style.color = 'var(--tm-black)';
btnToggle.textContent = "Start";
btnReset.style.display = 'none';
});