forked from Online-Timer/Online-Timer.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStopwatch_script.js
77 lines (72 loc) · 1.65 KB
/
Stopwatch_script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
let pause=true;
let time = 0;
let transt="";
let intervalId;
function f0(t){
if(t<10){
return '0'+t;
}
return t;
}
function sp(){
if(pause){
document.getElementById("sp").innerText = "pause";
pause=false;
if (intervalId) {
clearInterval(intervalId);
}
intervalId=setInterval(function () {
if (!pause) {
time++;
load();
}
}, 10);
}
else{
document.getElementById("sp").innerText = "resume";
pause=true;
}
}
function sty(){
var Element = document.getElementById("sty");
var themeLink = document.getElementById("theme");
if(Element.src.includes("light.png")){
Element.src="dark.png";
themeLink.setAttribute("href", "light_style.css");
sessionStorage.setItem("theme", "light_style.css");
}
else{
Element.src="light.png";
themeLink.setAttribute("href", "dark_style.css");
sessionStorage.setItem("theme", "dark_style.css");
}
}
function reset(){
document.getElementById("sp").innerText = "start";
pause=true;
time=0;
load();
}
function show(t){
let ms=t%100;
t-=ms;
t/=100;
let s=t%60;
t-=s;
t/=60;
let m=t%60;
t-=m;
t/=60;
return f0(t)+":"+f0(m)+":"+f0(s)+"."+f0(ms);
}
function load(){
transt = show(time);
document.getElementById("output").innerText = transt;
}
function loadtheme(){
if(sessionStorage.getItem("theme")==="light_style.css")sty();
}
window.onload = function(){
load();
loadtheme()
}