Created
May 11, 2020 10:10
-
-
Save zarc1411/5b155b158a5a77da089537f7f018204b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const currentTime = document.getElementById('timerCircle'); | |
const currentSessionDuration = document.getElementById('sessionDuration'); | |
const decreaseSessionTimeButton = document.getElementById('decreaseSessionTime'); | |
function appendZeroIfNeeded(){ | |
let currentMinutes = parseInt(currentTime.innerText.split(':')[0]); | |
if(currentMinutes<11){ | |
currentSessionDuration.innerText = '0'+currentSessionDuration.innerText; | |
} | |
} | |
decreaseSessionTimeButton.addEventListener('click' , ()=>{ | |
if(currentSessionDuration.innerText>0){ | |
currentSessionDuration.innerText = --currentSessionDuration.innerText; | |
appendZeroIfNeeded(); | |
currentTime.innerText = currentSessionDuration.innerText+':00'; | |
} | |
}); | |
const increaseSessionTimeButton = document.getElementById('increaseSessionTime'); | |
increaseSessionTimeButton.addEventListener('click' , ()=>{ | |
if(currentSessionDuration.innerText<60){ | |
currentSessionDuration.innerText = ++currentSessionDuration.innerText; | |
} | |
}); | |
const currentBreakDuration = document.getElementById('breakDuration'); | |
const decreaseBreakTimeButton = document.getElementById('decreaseBreakTime'); | |
decreaseBreakTimeButton.addEventListener('click' , ()=>{ | |
if(currentBreakDuration.innerText>0){ | |
currentBreakDuration.innerText = --currentBreakDuration.innerText; | |
} | |
}); | |
const increaseBreakTimeButton = document.getElementById('increaseBreakTime'); | |
increaseBreakTimeButton.addEventListener('click' , ()=>{ | |
if(currentBreakDuration.innerText<60){ | |
currentBreakDuration.innerText = ++currentBreakDuration.innerText; | |
} | |
}); | |
const startTimerButton = document.getElementById('play'); | |
function showCurrentTimeLeft(e){ | |
setInterval(function(){ | |
let currentSeconds = parseInt(currentTime.innerText.split(':')[1]); | |
let currentMinutes = parseInt(currentTime.innerText.split(':')[0]); | |
console.log(currentSeconds); | |
if(currentSeconds==0){ | |
currentMinutes -= 1; | |
currentTime.innerText = currentMinutes+':'+59; | |
} | |
else{ | |
let extraZeroInMinutes = ''; | |
let extraZeroInSeconds = ''; | |
if(currentMinutes<11){ | |
extraZeroInMinutes = '0'; | |
} | |
if(currentSeconds<11){ | |
extraZeroInSeconds = '0'; | |
} | |
currentTime.innerText = extraZeroInMinutes+currentMinutes+':'+extraZeroInSeconds+(currentSeconds-1); | |
} | |
if(currentSeconds == 0 && currentMinutes == 0){ | |
clearInterval(showCurrentTimeLeft); | |
} | |
},1000); | |
} | |
startTimerButton.addEventListener('click' , showCurrentTimeLeft); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment