-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.htm
129 lines (109 loc) · 4.47 KB
/
index.htm
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="clock-symbol-of-circular-shape-svgrepo-com.svg" sizes="any" type="image/svg+xml">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<title>Contador Regresivo</title>
</head>
<body>
<div class="modal modal-sheet position-static d-block p-4 py-md-5" tabindex="-1" role="dialog" id="modalTour">
<div class="modal-dialog" role="document">
<div class="modal-content rounded-4 shadow">
<div class="modal-body p-5 text-center">
<img src="https://edge.fscdn.org/assets/static/media/familysearch-tree.dc22204d2135c739e39d0af7d519e182.svg">
<h2 class="fw-bold mb-0 text-center" >Cuenta Regresiva</h2>
<p class="display-1 text-center" id="counter"> 20:00</p>
<p class="text-center" id="startCount">Veces Iniciado: 0</p>
<button id="startButton" class="btn btn-lg btn-primary mt-5 w-100">Iniciar</button>
</div>
</div>
</div>
</div>
<script>
let count = 0;
let running = false;
let interval;
let minutes = 20;
const startButton = document.getElementById('startButton');
const counterDisplay = document.getElementById('counter');
function startStop() {
if (!running) {
count++;
updateStartCount();
startButton.textContent = 'Detener';
startTimer();
} else {
clearInterval(interval);
running = false;
startButton.textContent = 'Iniciar';
}
}
function startTimer() {
let seconds = minutes * 60;
interval = setInterval(() => {
seconds--;
if (seconds < 0) {
clearInterval(interval);
running = false;
startButton.textContent = 'Iniciar';
alertTimeOver();
return;
}
displayTimeLeft(seconds);
}, 1000);
running = true;
}
function displayTimeLeft(seconds) {
const minutes = Math.floor(seconds / 60);
const remainderSeconds = seconds % 60;
const display = `${minutes}:${remainderSeconds < 10 ? '0' : ''}${remainderSeconds}`;
counterDisplay.textContent = display;
// Actualizar el título de la página con el tiempo restante
document.title = display + " | Cuenta regresiva";
// Comunicarse con el Service Worker
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({
action: 'updateTitle',
title: display
});
}
}
function updateStartCount() {
document.getElementById('startCount').textContent = `Veces Iniciado: ${count}`;
}
function alertTimeOver() {
// Cambiar título de la pestaña si está en segundo plano
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
document.title = "¡Tiempo terminado!";
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({
action: 'updateTitle',
title: "¡Tiempo terminado!"
});
}
}
});
// Reproducir sonido
const audio = new Audio('beep.mp3');
audio.play();
// Mostrar alerta
alert("¡Tiempo terminado!");
}
startButton.addEventListener('click', startStop);
// Registrar el Service Worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(reg => {
console.log('Service Worker registrado correctamente!', reg);
}).catch(err => {
console.error('Error al registrar el Service Worker:', err);
});
}
</script>
</body>
</html>