start/stop with spacebar

master
Matt Huntington 6 years ago
parent e283da0820
commit 5f3cd02c6c

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

Loading…
Cancel
Save