Temporizador Regresivo

Estamos en Práctica - Actividad #1

00:00:05
Instituto de Tecnologías para la Educación (ITED)
`; // Adjust width and height for a more compact popup popupWindowRef = window.open('', 'TimerPopup', 'width=320,height=150,resizable=yes,scrollbars=no,status=no,menubar=no,toolbar=no,location=no'); if (popupWindowRef) { popupWindowRef.document.write(popupHtml); popupWindowRef.document.close(); // Important for some browsers setOtherControlsEnabled(false); updateButtonStates(); // Update the main button to "close" icon// Periodically check if the popup was closed by the user popupUpdateInterval = setInterval(() => { if (popupWindowRef && popupWindowRef.closed) { clearInterval(popupUpdateInterval); popupWindowRef = null; setOtherControlsEnabled(true); updateButtonStates(); } }, 500);} else { alert("No se pudo abrir la ventana emergente. Por favor, revisa la configuración de tu navegador."); } } } // Listen for messages from popup (e.g., if it's closed) window.addEventListener('message', function(event) { if (event.data && event.data.type === 'POPUP_CLOSED') { if (popupWindowRef) { // Ensure we are tracking a popup clearInterval(popupUpdateInterval); popupWindowRef = null; // Mark as closed setOtherControlsEnabled(true); updateButtonStates(); } } });popupTimerButton.addEventListener('click', toggleTimerPopup); // closeTimerPopupButton listener is removedfunction timerTick() { if (timeLeftInSeconds > 0) { timeLeftInSeconds--; } else { clearInterval(timerInterval); timerInterval = null; timesUpMessage.classList.remove('hidden'); if (synth) { try { synth.triggerAttackRelease("C5", "8n", Tone.now()); synth.triggerAttackRelease("G4", "8n", Tone.now() + 0.2); } catch (error) { console.error("Error playing sound:", error); } } } updateTimerDisplay(); // This will also postMessage to popup if open if (!popupWindowRef || popupWindowRef.closed) { // Only update main button states if popup is not open updateButtonStates(); } }openSettingsButton.addEventListener('click', () => { modalTitleInput.value = mainTitleElement.textContent; modalHoursInput.value = String(Math.floor(originalDurationInSeconds / 3600)).padStart(2, '0'); modalMinutesInput.value = String(Math.floor((originalDurationInSeconds % 3600) / 60)).padStart(2, '0'); modalSecondsInput.value = String(originalDurationInSeconds % 60).padStart(2, '0'); settingsModal.classList.remove('hidden'); });cancelSettingsButton.addEventListener('click', () => { settingsModal.classList.add('hidden'); });saveSettingsButton.addEventListener('click', () => { mainTitleElement.textContent = modalTitleInput.value.trim() || "Estamos en Práctica - Actividad #1"; const h = parseInt(modalHoursInput.value) || 0; const m = parseInt(modalMinutesInput.value) || 0; const s = parseInt(modalSecondsInput.value) || 0; originalDurationInSeconds = (h * 3600) + (m * 60) + s; clearInterval(timerInterval); timerInterval = null; isPaused = false; timeLeftInSeconds = originalDurationInSeconds; if (timeLeftInSeconds <= 0) { timeLeftInSeconds = 1; originalDurationInSeconds = 1; modalSecondsInput.value = "1"; } updateTimerDisplay(); // Update main and potentially popup timesUpMessage.classList.add('hidden'); if (!popupWindowRef || popupWindowRef.closed) updateButtonStates(); settingsModal.classList.add('hidden'); });startButton.addEventListener('click', async () => { if (!synth) await initializeAudio(); timesUpMessage.classList.add('hidden'); if (isPaused) { isPaused = false; } else { if (timeLeftInSeconds <= 0) { timeLeftInSeconds = originalDurationInSeconds; if (timeLeftInSeconds <= 0) { timesUpMessage.textContent = "Establece una duración válida desde la configuración."; timesUpMessage.classList.remove('hidden'); setTimeout(() => timesUpMessage.classList.add('hidden'), 3000); return; } } isPaused = false; // Ensure not paused when starting fresh } clearInterval(timerInterval); // Clear any existing interval before starting a new one timerInterval = setInterval(timerTick, 1000); if (!popupWindowRef || popupWindowRef.closed) updateButtonStates(); });pauseButton.addEventListener('click', () => { if (timerInterval && !isPaused) { clearInterval(timerInterval); isPaused = true; // Set paused state if (!popupWindowRef || popupWindowRef.closed) updateButtonStates(); } });resetButton.addEventListener('click', async () => { if (!synth) await initializeAudio(); clearInterval(timerInterval); timerInterval = null; isPaused = false; timeLeftInSeconds = originalDurationInSeconds; updateTimerDisplay(); // Update main and potentially popup timesUpMessage.classList.add('hidden'); if (!popupWindowRef || popupWindowRef.closed) updateButtonStates(); });document.addEventListener('DOMContentLoaded', () => { mainTitleElement.textContent = modalTitleInput.value; updateTimerDisplay(); updateButtonStates(); });