start/stop with spacebar

master
Matt Huntington 6 years ago
parent e283da0820
commit 5f3cd02c6c

@ -5,7 +5,6 @@
MVP MVP
- display how many 5/10min blocks have passed - display how many 5/10min blocks have passed
- start/stop with spacebar
- don't confirm close if time displayed is 0 - don't confirm close if time displayed is 0
- set alarm for after certain times have passed - set alarm for after certain times have passed
- cleanup - cleanup
@ -53,16 +52,7 @@ const displayTime = () => {
document.querySelector('code').innerHTML = formatSeconds(totalSeconds); document.querySelector('code').innerHTML = formatSeconds(totalSeconds);
} }
const updateSavedPreviousSeconds = () => { const start = (event) => {
savedPreviousSeconds += getAccumulatedSeconds(Date.now(), startTime);
}
document.querySelector('code').innerHTML = formatSeconds(savedPreviousSeconds);
if(savedPreviousSeconds !== 0){
document.querySelector('#reset').disabled=false;
}
document.querySelector('#start').addEventListener('click', (event) => {
startTime = Date.now(); startTime = Date.now();
running = true; running = true;
document.querySelector('body').classList.add('running'); document.querySelector('body').classList.add('running');
@ -70,9 +60,9 @@ document.querySelector('#start').addEventListener('click', (event) => {
document.querySelector('#stop').disabled=false; document.querySelector('#stop').disabled=false;
document.querySelector('#reset').disabled=true; document.querySelector('#reset').disabled=true;
windowInterval = window.setInterval(displayTime,1000) windowInterval = window.setInterval(displayTime,1000)
}) };
document.querySelector('#stop').addEventListener('click', (event) => { const stop = (event) => {
updateSavedPreviousSeconds(); updateSavedPreviousSeconds();
running = false; running = false;
document.querySelector('body').classList.remove('running'); document.querySelector('body').classList.remove('running');
@ -80,7 +70,20 @@ document.querySelector('#stop').addEventListener('click', (event) => {
document.querySelector('#stop').disabled=true; document.querySelector('#stop').disabled=true;
document.querySelector('#reset').disabled=false; document.querySelector('#reset').disabled=false;
window.clearInterval(windowInterval) window.clearInterval(windowInterval)
}) };
const updateSavedPreviousSeconds = () => {
savedPreviousSeconds += getAccumulatedSeconds(Date.now(), startTime);
}
document.querySelector('code').innerHTML = formatSeconds(savedPreviousSeconds);
if(savedPreviousSeconds !== 0){
document.querySelector('#reset').disabled=false;
}
document.querySelector('#start').addEventListener('click', start)
document.querySelector('#stop').addEventListener('click', stop)
document.querySelector('#reset').addEventListener('click', (event) => { document.querySelector('#reset').addEventListener('click', (event) => {
savedPreviousSeconds = 0; savedPreviousSeconds = 0;
@ -88,6 +91,16 @@ document.querySelector('#reset').addEventListener('click', (event) => {
document.querySelector('#reset').disabled=true; document.querySelector('#reset').disabled=true;
}) })
document.querySelector('body').addEventListener('keyup', (event) => {
if(event.keyCode === 32){
if(running){
stop();
} else {
start();
}
}
})
window.onbeforeunload = function(){ window.onbeforeunload = function(){
if(running){ if(running){
updateSavedPreviousSeconds(); updateSavedPreviousSeconds();

Loading…
Cancel
Save