diff --git a/Pomodoro-Timer/Preview.png b/Pomodoro-Timer/Preview.png new file mode 100644 index 00000000..ec587169 Binary files /dev/null and b/Pomodoro-Timer/Preview.png differ diff --git a/Pomodoro-Timer/README.md b/Pomodoro-Timer/README.md new file mode 100644 index 00000000..7d7090d7 --- /dev/null +++ b/Pomodoro-Timer/README.md @@ -0,0 +1,10 @@ +# Pomodoro-Timer + +# Description + +* Pomodoro is an excellent technique for increasing your productivity and helps you overcome procrastination. +* Set your timer and focus on a single task until the timer rings. When your session ends, mark off one pomodoro and record what you completed. Then enjoy a five-minute break. +* Created using Vanilla Javascript. + +# Snapshot +![Preview]() diff --git a/Pomodoro-Timer/app.js b/Pomodoro-Timer/app.js new file mode 100644 index 00000000..12a1a32f --- /dev/null +++ b/Pomodoro-Timer/app.js @@ -0,0 +1,127 @@ +const sessionLength= document.querySelector('#sessionLength'); +const breakLength= document.querySelector('#breakLength'); +const addSession= document.querySelector('#add-session'); +const subSession= document.querySelector('#sub-session'); +const addBreak= document.querySelector('#add-break'); +const subBreak= document.querySelector('#sub-break'); + +const startButton= document.querySelector('.start'); +const stopButton= document.querySelector('.stop'); +const resetButton= document.querySelector('.reset'); + +const clock= document.querySelector('.clock'); +const session= document.querySelector('.session'); + +startButton.addEventListener('click',startPomodoro); +resetButton.addEventListener('click',resetPomodoro); +stopButton.addEventListener('click',stopPomodoro); + +let workTime= sessionLength.innerHTML; +let breakTime= breakLength.innerHTML; +let timerID; +let timeStart; +addSession.addEventListener('click',()=>{ + if(workTime<60){workTime++;} + sessionLength.innerHTML= workTime; + clock.innerHTML= workTime+':00'; + console.log(workTime); +}) +subSession.addEventListener('click',()=>{ + if(workTime>1){workTime--;} + sessionLength.innerHTML= workTime; + clock.innerHTML= workTime+':00'; +}) +addBreak.addEventListener('click',()=>{ + if(breakTime<60){breakTime++;} + breakLength.innerHTML=breakTime; +}) +subBreak.addEventListener('click',()=>{ + if(breakTime>1){breakTime--;} + breakLength.innerHTML=breakTime; +}) +function stopPomodoro(){ + addSession.disabled=false; + subSession.disabled=false; + addBreak.disabled=false; + subBreak.disabled=false; + startButton.disabled= false; + clearInterval(timerID); + session.innerHTML="Work Session"; + clock.innerHTML=sessionLength.innerHTML+":00"; +} + +function resetPomodoro(){ + addSession.disabled=true; + subSession.disabled=true; + addBreak.disabled=true; + subBreak.disabled=true; + startButton.disabled= true; + clearInterval(timerID); + document.querySelector('.timer').style.borderColor="#BD3737"; + document.querySelector('.timer').style.backgroundColor="#942222"; + timeStart= new Date().getTime(); + session.innerHTML="Work Session"; + totalSeconds= sessionLength.innerHTML * 60; + timerID= setInterval(changeTime,990); +} +function startPomodoro(){ + addSession.disabled=true; + subSession.disabled=true; + addBreak.disabled=true; + subBreak.disabled=true; + startButton.disabled= true; + document.querySelector('.timer').style.borderColor="#BD3737"; + document.querySelector('.timer').style.backgroundColor="#942222"; + timeStart= new Date().getTime(); + timerID= setInterval(changeTime,990); + totalSeconds= sessionLength.innerHTML * 60; +} +let minutes; +let seconds; +let totalSeconds; +function changeTime(){ + let timeNow= new Date().getTime(); + let diff= Math.floor((timeNow-timeStart)/1000); + console.log(totalSeconds+" "+diff); + let temp= totalSeconds-diff; + if(temp==2){ + playSound(); + } + if(diff>=totalSeconds){ + changeSessions(); + } + else{ + minutes= Math.floor(temp/60); + seconds= Math.floor(temp-minutes*60); + if(seconds<10){seconds='0'+seconds;} + clock.innerHTML= minutes+':'+seconds; + } +} + +function changeSessions(){ + clearInterval(timerID); + timeStart= new Date().getTime(); + if(session.innerHTML=="Work Session"){ + session.innerHTML="Break Session"; + clock.innerHTML=breakLength.innerHTML+':00'; + totalSeconds= breakLength.innerHTML * 60; + document.querySelector('.timer').style.borderColor="#a31cd4"; + document.querySelector('.timer').style.backgroundColor="#7b1cd4"; + } + else{ + session.innerHTML="Work Session"; + clock.innerHTML=sessionLength.innerHTML+':00'; + totalSeconds= sessionLength.innerHTML * 60; + document.querySelector('.timer').style.borderColor="#BD3737"; + document.querySelector('.timer').style.backgroundColor="#942222"; + } + timerID=setInterval(changeTime,990); +} + +function playSound() { + + var mp3 = "http://soundbible.com/grab.php?id=1746&type=mp3"; + var audio = new Audio(mp3); + audio.play(); + + } \ No newline at end of file diff --git a/Pomodoro-Timer/index.html b/Pomodoro-Timer/index.html new file mode 100644 index 00000000..4439bd2c --- /dev/null +++ b/Pomodoro-Timer/index.html @@ -0,0 +1,56 @@ + + +
+ + + + + + + +