1stopWatchSidebarStatus = false;
 2breakTime = 5*60*1000;
 3workTime = 25*60*1000;
 4
 5
 6
 7breakTimeRound = Math.round(breakTime/1000);
 8workTimeRound = Math.round(workTime/1000);
 9
10startTime = new Date();
11currentState = "Work";
12startedState = false;
13stopwatchPaused = false;
14stopwatchPauseTime = new Date();
15
16
17
18function toggleStopwatchSidebar(){
19    if(stopWatchSidebarStatus){
20        document.getElementById("stopwatch-sidebar").style = "";
21        stopWatchSidebarStatus = false;
22    } else {
23        document.getElementById("stopwatch-sidebar").style.left = "-2px";
24        document.getElementById("stopwatch-sidebar").style.border = "white 1px solid";
25        stopWatchSidebarStatus = true;
26    }
27}
28
29function startStopwatch(){
30    if (!stopwatchPaused){
31        startTime = new Date();
32        startedState = true;
33    } 
34    else {
35        startTime = new Date()-stopwatchPauseTime;
36        startedState = true;
37        stopwatchPaused=false;
38    }
39    
40}
41
42function resetStopwatch(){
43    startTime = new Date();
44    startedState = false;
45    stopwatchPaused=false;
46}
47
48function pauseStopwatch(){
49    startedState = false;
50    stopwatchPaused = true;
51    stopwatchPauseTime = (new Date() - startTime);
52}
53
54function updateStopwatch(){
55    if(startedState){
56        deltaTime = (new Date() - startTime)
57        deltaTimeRound = Math.round(deltaTime/1000);
58        if (currentState == "Work"){
59        progress = deltaTime/workTime;
60        stateTimeRound = workTimeRound
61        } else{
62            progress = deltaTime/breakTime;
63            stateTimeRound = breakTimeRound
64        }
65        document.getElementById("stopwatch-progress-bar-infill").style.width = `${progress*320}px`;
66        document.getElementById("stopwatch-progress-bar-text").innerHTML = `${String(Math.floor(deltaTimeRound/3600)).padStart(2, '0')}:${String(Math.floor(deltaTimeRound/60)%60).padStart(2, '0')}:${String(deltaTimeRound%60).padStart(2, '0')} / ${String(Math.floor(stateTimeRound/3600)).padStart(2, '0')}:${String(Math.floor(stateTimeRound/60)%60).padStart(2, '0')}:${String(stateTimeRound%60).padStart(2, '0')} (${currentState})`
67        if (progress > 1){
68            if (currentState == "Work"){
69                currentState = "Break";
70                } else{
71                    currentState = "Work";
72                }
73            startTime = new Date();
74        }
75    }
76    }
77
78setInterval(updateStopwatch,100);