-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (48 loc) · 1.68 KB
/
Copy pathscript.js
File metadata and controls
56 lines (48 loc) · 1.68 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
// script.js con Pop-up de Configuración
let totalTime = 900; // Tiempo por defecto: 15 minutos (900 segundos)
let remainingTime = totalTime;
let timerElement = document.getElementById('timer');
// Mostrar pop-up para configurar el tiempo
function showTimePopup() {
let minutes = prompt("Ingresa la duración en minutos (ej. 15 para 15 minutos):", "15");
let seconds = parseInt(minutes) * 60;
if (!isNaN(seconds) && seconds > 0) {
totalTime = seconds;
remainingTime = totalTime;
timerElement.textContent = formatTime(remainingTime);
}
}
function updateBackgroundColor() {
let elapsed = totalTime - remainingTime;
let fraction = elapsed / totalTime;
if (fraction <= 1/3) {
document.body.style.backgroundColor = 'green';
timerElement.style.color = 'white';
} else if (fraction <= 2/3) {
document.body.style.backgroundColor = 'yellow';
timerElement.style.color = 'black';
} else {
document.body.style.backgroundColor = 'red';
timerElement.style.color = 'white';
}
}
function formatTime(seconds) {
let mins = Math.floor(seconds / 60);
let secs = seconds % 60;
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
}
function startTimer() {
let timerInterval = setInterval(() => {
if (remainingTime <= 0) {
clearInterval(timerInterval);
} else {
remainingTime--;
timerElement.textContent = formatTime(remainingTime);
updateBackgroundColor();
}
}, 1000);
}
// Mostrar pop-up al cargar la página
showTimePopup();
timerElement.textContent = formatTime(remainingTime);
startTimer();