-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path番茄时钟.html
More file actions
119 lines (108 loc) · 3.58 KB
/
Copy path番茄时钟.html
File metadata and controls
119 lines (108 loc) · 3.58 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
<title>番茄时钟</title>
<meta charset="UTF-8">
<style>
body {
background-color: #FDF5E6;
font-family: Arial, sans-serif;
color: #A0522D;
text-align: center;
}
h1 {
margin-top: 50px;
font-size: 36px;
font-weight: bold;
}
#timer {
margin-top: 30px;
font-size: 48px;
font-weight: bold;
}
button {
padding: 10px 20px;
font-size: 18px;
border-radius: 10px;
border: none;
margin-bottom: 20px;
background-color: #A0522D;
color: white;
cursor: pointer;
}
input[type=number] {
padding: 10px;
font-size: 18px;
border-radius: 10px;
border: none;
margin: 10px;
}
</style>
</head>
<body>
<h1>番茄时钟</h1>
<div>
工作时间(分钟):<input type="number" id="workTime" min="1" value="25">
休息时间(分钟):<input type="number" id="breakTime" min="1" value="5">
</div>
<button onclick="startWork()">开始工作</button>
<div id="timer">25:00</div>
<script>
let workTotalTime = 1500; // 默认为 25 分钟
let breakTotalTime = 300; // 默认为 5 分钟
let timer; // 定时器
let isWorking = false; // 是否工作状态标识
const startWork = () => {
const workTime = document.getElementById('workTime').value;
const breakTime = document.getElementById('breakTime').value;
if (workTime > 0) {
workTotalTime = workTime * 60;
}
if (breakTime > 0) {
breakTotalTime = breakTime * 60;
}
document.querySelector('body').requestFullscreen();
displayTime(workTotalTime);
isWorking = true;
timer = setInterval(() => {
if (isWorking) {
workTotalTime--;
if (workTotalTime <= 0) {
clearInterval(timer);
startBreak();
} else {
displayTime(workTotalTime);
}
} else {
breakTotalTime--;
if (breakTotalTime <= 0) {
clearInterval(timer);
document.querySelector('body').exitFullscreen();
alert('休息时间结束!');
} else {
displayTime(breakTotalTime);
}
}
}, 1000);
}
const startBreak = () => {
displayTime(breakTotalTime);
isWorking = false;
timer = setInterval(() => {
if (breakTotalTime <= 0) {
clearInterval(timer);
startWork();
} else {
breakTotalTime--;
displayTime(breakTotalTime);
}
}, 1000);
}
const displayTime = (time) => {
const minutes = Math.floor(time / 60).toString().padStart(2, '0');
const seconds = (time % 60).toString().padStart(2, '0');
document.getElementById('timer').innerHTML = `${minutes}:${seconds}`;
}
</script>
</body>
</html>