-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.close
183 lines (154 loc) · 4.09 KB
/
window.close
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//倒數計時網頁自動關閉
//使用Roplit線上工具
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>replit</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="countdown">
<p id="timer"></p>
<label class="switch" id="stopButton">
<input type="checkbox" id="toggleSwitch">
<span class="slider"></span>
</label>
</div>
<style>
/* styles.css */
/* styles.css */
body, html {
height: 100%;
margin: 0;
font-family: 'Courier New', Courier, monospace; /* 更改字體為等寬字型 */
display: flex;
justify-content: center;
align-items: center;
background-color: #f3f3f3;
}
#countdown {
padding: 20px;
border: 2px solid #000;
border-radius: 5px;
background: #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
#timer {
font-size: 4rem; /* 增加字體大小 */
font-weight: bold;
color: darkred; /* 設定字體顏色為深紅 */
}
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
background-color: red;
border-radius: 34px;
box-shadow: 0 0 10px #666;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
input:checked + .slider {
background-color: #ff0000;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider:before {
transform: translateX(26px);
}
/* 为“暫停/繼續”按钮添加类似的样式 */
#stopButton {
display: inline-block;
width: 60px;
height: 34px;
background-color: #ccc;
border-radius: 34px;
box-shadow: 0 0 10px #666;
color: white;
font-weight: bold;
text-align: center;
line-height: 34px;
cursor: pointer;
transition: background-color .4s;
}
#stopButton:hover {
background-color: #ff0000;
}
</style>
<script>
// switch.js
// switch.js
// switch.js
document.getElementById('toggleSwitch').addEventListener('change', function() {
if (this.checked) {
console.log('Switch ON');
} else {
console.log('Switch OFF');
}
});
var paused = false;
var timer = null;
var remainTime = 12000; // 初始60秒
function startTimer() {
var end = Date.now() + remainTime;
function tick() {
if (paused) {
clearInterval(timer);
return;
}
var now = Date.now();
remainTime = end - now;
if (remainTime <= 0) {
clearInterval(timer);
document.getElementById('timer').textContent = "🖕";
window.close(); // 计时结束时尝试关闭网页
return;
}
var seconds = Math.floor((remainTime / 1000) % 60);
seconds = seconds < 10 ? "0" + seconds : seconds;
document.getElementById('timer').textContent = seconds;
};
tick();
timer = setInterval(tick, 1000);
}
document.getElementById('stopButton').addEventListener('click', function() {
if (!paused) {
paused = true;
this.textContent = "繼續";
clearInterval(timer);
} else {
paused = false;
this.textContent = "暫停";
startTimer(); // 从剩余时间继续
}
});
startTimer(); // 初始化计时器
</script>
</body>
</html>