From 0d9c6196adb755cd8d9bbe2ef9df1f3d5da4d598 Mon Sep 17 00:00:00 2001 From: PethersonML Date: Mon, 17 Mar 2025 15:23:29 -0300 Subject: [PATCH 1/3] =?UTF-8?q?Adiciona=20convers=C3=A3o=20dos=20`Inputs`?= =?UTF-8?q?=20do=20HTML=20para=20`Segundos`=20e=20convers=C3=A3o=20dos=20`?= =?UTF-8?q?Segundos`=20para=20os=20`Inputs`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.js | 83 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/script.js b/script.js index 5cafba6..a623338 100644 --- a/script.js +++ b/script.js @@ -1,15 +1,42 @@ -let intervalInMillis = 10; - let timerStarted = false; -let millis = 0; -let seconds = 30; -let minutes = 0; -let hours = 0; +let seconds = 0; let intervalInstance; -document.getElementById("hour").value = hours; -document.getElementById("min").value = minutes; -document.getElementById("sec").value = seconds; +const convertInputsToSeconds = () => { + const hour = Number(document.getElementById("hour").value); + const min = Number(document.getElementById("min").value); + const sec = Number(document.getElementById("sec").value); + + seconds = sec; + + if( min > 0 ) + seconds += min * 60; + + if ( hour > 0 ) + seconds += hour * 3600; +} + +const convertSecondsToInputs = () => { + let hour = 0; + let min = 0; + let sec = 0; + + if( seconds > 3600 ){ + hour = Math.floor( seconds / 3600 ); + seconds = seconds % 3600; + } + + if( seconds > 60 ){ + min = Math.floor( seconds / 60); + sec = seconds % 60; + } else { + sec = seconds; + } + + document.getElementById("hour").value = hour < 10 && hour > 0 ? '0' + hour : hour == 0 ? '00' : hour; + document.getElementById("min").value = min < 10 && min > 0 ? '0' + min : min == 0 ? '00' : min; + document.getElementById("sec").value = sec < 10 && sec > 0 ? '0' + sec : sec == 0 ? '00' : sec; +} document.getElementById("startBtn").addEventListener("click", function () { timerStarted = true; @@ -17,7 +44,6 @@ document.getElementById("startBtn").addEventListener("click", function () { }); document.getElementById("pauseBtn").addEventListener("click", function () { - console.log("pause"); pause(); }); @@ -33,42 +59,17 @@ document.getElementById("toZeroBtn").addEventListener("click", function () { }); function run() { - hours = document.getElementById("hour").value; - minutes = document.getElementById("min").value; - seconds = document.getElementById("sec").value; - intervalInstance = setInterval(function () { if (timerStarted) { + convertInputsToSeconds(); seconds--; - if (seconds == 0) { - if (minutes > 0) { - minutes--; - - seconds = 0; - seconds = 59; - } else { - if (hours > 0) { - // sem condição - } else { - timerStarted = false; - clearInterval(intervalInstance); - } - } + if( seconds >= 0 ){ + convertSecondsToInputs(); + } else { + timerStarted = false; + clearInterval(intervalInstance); } - - if (minutes == 0) { - if (hours > 0) { - hours--; - minutes = 59; - } else { - // sem condição - } - } - - document.getElementById(`sec`).value = seconds; - document.getElementById(`min`).value = minutes; - document.getElementById(`hour`).value = hours; } }, 1000); } From e8002ed0e31194ee3221a5330b71cdea764b8204 Mon Sep 17 00:00:00 2001 From: PethersonML Date: Mon, 17 Mar 2025 23:27:49 -0300 Subject: [PATCH 2/3] =?UTF-8?q?-=20Adiciona=20fun=C3=A7=C3=B5es=20de=20`Ed?= =?UTF-8?q?i=C3=A7=C3=A3o;=20-=20Refatora=20boa=20parte=20do=20c=C3=B3digo?= =?UTF-8?q?=20feito=20at=C3=A9=20ent=C3=A3o;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 20 ++++--- script.js | 168 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 133 insertions(+), 55 deletions(-) diff --git a/index.html b/index.html index 189a3a0..9217e5c 100644 --- a/index.html +++ b/index.html @@ -6,39 +6,43 @@ Cronometro +
- + : - + : - +
+
- - -
+
- -
+ diff --git a/script.js b/script.js index a623338..f8884d2 100644 --- a/script.js +++ b/script.js @@ -1,66 +1,92 @@ let timerStarted = false; let seconds = 0; +let sec = 0; +let min = 0; +let hour = 0; let intervalInstance; -const convertInputsToSeconds = () => { - const hour = Number(document.getElementById("hour").value); - const min = Number(document.getElementById("min").value); - const sec = Number(document.getElementById("sec").value); +const timeInputs = document.querySelector('.input-stopwatch'); - seconds = sec; +const startBtn = document.getElementById("startBtn"); +const pauseBtn = document.getElementById("pauseBtn"); +const resetBtn = document.getElementById("resetBtn"); +const editBtn = document.getElementById("editBtn"); +const cancelEditBtn = document.getElementById("cancelEditBtn"); +const confirmEditBtn = document.getElementById("confirmEditBtn"); - if( min > 0 ) - seconds += min * 60; +startBtn.addEventListener("click", function () { + if( !timerStarted ){ + timerStarted = true; + run(); + } +}); - if ( hour > 0 ) - seconds += hour * 3600; -} +pauseBtn.addEventListener("click", function () { + pause(); +}); -const convertSecondsToInputs = () => { - let hour = 0; - let min = 0; - let sec = 0; +resetBtn.addEventListener("click", function () { + reset(); +}); - if( seconds > 3600 ){ - hour = Math.floor( seconds / 3600 ); - seconds = seconds % 3600; - } +editBtn.addEventListener("click", function () { + document.querySelector('.js-stopwatch-button').classList.add('hide'); + document.querySelector('.js-edit-container-stopwatch').classList.remove('hide'); - if( seconds > 60 ){ - min = Math.floor( seconds / 60); - sec = seconds % 60; - } else { - sec = seconds; - } + timeInputs.querySelectorAll('input').forEach(input => input.disabled = false); - document.getElementById("hour").value = hour < 10 && hour > 0 ? '0' + hour : hour == 0 ? '00' : hour; - document.getElementById("min").value = min < 10 && min > 0 ? '0' + min : min == 0 ? '00' : min; - document.getElementById("sec").value = sec < 10 && sec > 0 ? '0' + sec : sec == 0 ? '00' : sec; -} + hour = Number(document.getElementById("hour").value); + min = Number(document.getElementById("min").value); + sec = Number(document.getElementById("sec").value); +}); -document.getElementById("startBtn").addEventListener("click", function () { - timerStarted = true; - run(); +document.querySelectorAll('.input-stopwatch input').forEach(input => { + input.addEventListener('input', function () { + let max = input.id === 'hour' ? 99 : 59; + let min = 0; + + const value = Number(input.value); + + if( value >= 0 && value < 10 ){ + input.value = '0' + value; + } else { + input.value = value; + } + + if( value < min ) + input.value = '00'; + + if( value > max ) + input.value = max; + + }); }); -document.getElementById("pauseBtn").addEventListener("click", function () { - pause(); +cancelEditBtn.addEventListener("click", function () { + document.querySelector('.js-stopwatch-button').classList.remove('hide'); + document.querySelector('.js-edit-container-stopwatch').classList.add('hide'); + + timeInputs.querySelectorAll('input').forEach(input => input.disabled = true); + + document.getElementById("hour").value = hour >= 0 && hour < 10 ? '0' + hour : hour; + document.getElementById("min").value = min >= 0 && min < 10 ? '0' + min : min; + document.getElementById("sec").value = sec >= 0 && sec < 10 ? '0' + sec : sec; }); -document.getElementById("toZeroBtn").addEventListener("click", function () { - pause(); - hours = 0; - minutes = 0; - seconds = 30; +confirmEditBtn.addEventListener("click", function () { + document.querySelector('.js-stopwatch-button').classList.remove('hide'); + document.querySelector('.js-edit-container-stopwatch').classList.add('hide'); - document.getElementById("hour").value = hours; - document.getElementById("min").value = minutes; - document.getElementById("sec").value = seconds; + timeInputs.querySelectorAll('input').forEach(input => input.disabled = true); }); function run() { - intervalInstance = setInterval(function () { - if (timerStarted) { + if( timerStarted ) { + startBtn.classList.add('hide'); + pauseBtn.classList.remove('hide'); + editBtn.disabled = true; + + intervalInstance = setInterval(function () { convertInputsToSeconds(); seconds--; @@ -69,17 +95,65 @@ function run() { } else { timerStarted = false; clearInterval(intervalInstance); + startBtn.classList.remove('hide'); + pauseBtn.classList.add('hide'); + editBtn.disabled = false; } - } - }, 1000); + }, 1000); + } +} + +const convertInputsToSeconds = () => { + hour = Number(document.getElementById("hour").value); + min = Number(document.getElementById("min").value); + sec = Number(document.getElementById("sec").value); + + seconds = sec; + + if( min > 0 ) + seconds += min * 60; + + if ( hour > 0 ) + seconds += hour * 3600; +} + +const convertSecondsToInputs = () => { + hour = 0; + min = 0; + sec = 0; + + if( seconds > 3600 ){ + hour = Math.floor( seconds / 3600 ); + seconds = seconds % 3600; + } + + if( seconds > 60 ){ + min = Math.floor( seconds / 60); + sec = seconds % 60; + } else { + sec = seconds; + } + + document.getElementById("hour").value = hour >= 0 && hour < 10 ? '0' + hour : hour; + document.getElementById("min").value = min >= 0 && min < 10 ? '0' + min : min; + document.getElementById("sec").value = sec >= 0 && sec < 10 ? '0' + sec : sec; } function pause() { timerStarted = false; clearInterval(intervalInstance); + startBtn.classList.remove('hide'); + pauseBtn.classList.add('hide'); + editBtn.disabled = false; } -function stop() { +function reset() { timerStarted = false; + clearInterval(intervalInstance); + document.getElementById("hour").value = '00'; + document.getElementById("min").value = '00'; + document.getElementById("sec").value = 30; + startBtn.classList.remove('hide'); + pauseBtn.classList.add('hide'); + editBtn.disabled = false; } -// functio From 70fb9c2b7c27784779b5bf35c0e0fec6f0c04c1d Mon Sep 17 00:00:00 2001 From: PethersonML Date: Tue, 18 Mar 2025 02:07:10 -0300 Subject: [PATCH 3/3] =?UTF-8?q?-=20Adiciona=20fun=C3=A7=C3=B5es=20de=20`Fu?= =?UTF-8?q?llscreen`=20e=20ultimos=2010sec=20ficando=20em=20destaque;=20-?= =?UTF-8?q?=20Refatora=20todo=20o=20c=C3=B3digo;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 8 +++- script.js | 120 ++++++++++++++++++++++++++++++++++++----------------- style.css | 30 +++++++++++++- 3 files changed, 118 insertions(+), 40 deletions(-) diff --git a/index.html b/index.html index 9217e5c..6d010b9 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ Cronometro - +
@@ -16,8 +16,12 @@
+
+ +
+
-