-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.html
More file actions
247 lines (223 loc) · 8.29 KB
/
Copy pathtimer.html
File metadata and controls
247 lines (223 loc) · 8.29 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>タイマー</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
:root{
--background-light: #ffffff;
--background-dark: #000000;
--element-light: #185af2;
--element-dark: #185af2;
--text-light: #ffffff;
--text-dark: #1c1c1c;
}
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background:var(--background-light);
}
.timer {
font-size: 2em;
margin: 20px;
}
.controls {
display: flex;
gap: 10px;
}
.controls button {
padding: 10px 20px;
font-size: 1em;
display: flex;
align-items: center;
gap: 5px;
}
.time-inputs input {
width: 60px;
text-align: center;
font-size: 1.3em;
border-radius:10px;
border: none;
transition: all 0.5s ease-out;
background:var(--text-light);
}
#startStopButton{
background:var(--element-dark);
color:#fff;
border-radius:100px;
border:none;
}
#resetButton{
background:var(--text-light);
color:#fff;
border-radius:100px;
border:none;
color:#000;
}
@media (prefers-color-scheme: dark) {
body{
background:var(--background-dark);
color:#fff;
}
.time-inputs input{
background:var(--text-dark);
color:#fff;
}
#startStopButton{
background:var(--element-light);
color:#000;
}
#resetButton{
background:var(--text-dark);
color:var(--element-light);
}
}
</style>
<script>
function addToDisplay(value) {
document.getElementById('display').value += value;
}
function clearDisplay() {
document.getElementById('display').value = '';
}
function calculate() {
try {
document.getElementById('display').value = eval(document.getElementById('display').value);
} catch(error) {
document.getElementById('display').value = 'Error';
}
}
// Function to read the base color from localStorage and apply it
function applyStoredColor() {
// Retrieve the base color from localStorage
const baseColor = localStorage.getItem('baseColor');
// Check if baseColor exists
if (baseColor) {
// Apply base color to the page
const lightBackground = lightenColor(baseColor, 0.8); // Example function to lighten color
const lightElement = lightenColor(baseColor, 0.5);
const lightTextColor = lightenColor(baseColor, 0.7);
const darkBackground = darkenColor(baseColor, 0.9); // Example function to darken color
const darkElement = darkenColor(baseColor, 0.4);
const darkTextColor = darkenColor(baseColor, 0.7);
document.documentElement.style.setProperty('--background-light', lightBackground);
document.documentElement.style.setProperty('--element-light', lightElement);
document.documentElement.style.setProperty('--text-light', lightTextColor);
document.documentElement.style.setProperty('--background-dark', darkBackground);
document.documentElement.style.setProperty('--element-dark', darkElement);
document.documentElement.style.setProperty('--text-dark', darkTextColor);
} else {
console.warn('No baseColor found in localStorage.');
}
}
// Function to lighten color
function lightenColor(color, amount) {
let r = parseInt(color.slice(1, 3), 16);
let g = parseInt(color.slice(3, 5), 16);
let b = parseInt(color.slice(5, 7), 16);
r = Math.min(255, Math.floor(r + (255 - r) * amount));
g = Math.min(255, Math.floor(g + (255 - g) * amount));
b = Math.min(255, Math.floor(b + (255 - b) * amount));
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
}
// Function to darken color
function darkenColor(color, amount) {
let r = parseInt(color.slice(1, 3), 16);
let g = parseInt(color.slice(3, 5), 16);
let b = parseInt(color.slice(5, 7), 16);
r = Math.max(0, Math.floor(r * (1 - amount)));
g = Math.max(0, Math.floor(g * (1 - amount)));
b = Math.max(0, Math.floor(b * (1 - amount)));
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
}
// Apply the stored base color when the page loads
window.addEventListener('DOMContentLoaded', applyStoredColor);
</script>
</head>
<body>
<div class="timer">
<div class="time-inputs">
<input type="text" id="hoursInput" value="00"> :
<input type="text" id="minutesInput" value="00"> :
<input type="text" id="secondsInput" value="00">
</div>
</div>
<div class="controls">
<button id="startStopButton"><span class="material-icons">play_arrow</span>開始</button>
<button id="resetButton"><span class="material-icons">refresh</span>リセット</button>
</div>
<script>
let timerInterval;
let timeRemaining = 0;
let timerRunning = false;
const hoursInput = document.getElementById('hoursInput');
const minutesInput = document.getElementById('minutesInput');
const secondsInput = document.getElementById('secondsInput');
const startStopButton = document.getElementById('startStopButton');
const resetButton = document.getElementById('resetButton');
function updateTimeDisplay() {
const hours = Math.floor(timeRemaining / 3600).toString().padStart(2, '0');
const minutes = Math.floor((timeRemaining % 3600) / 60).toString().padStart(2, '0');
const seconds = (timeRemaining % 60).toString().padStart(2, '0');
hoursInput.value = hours;
minutesInput.value = minutes;
secondsInput.value = seconds;
}
function startTimer() {
if (timerRunning) return;
timerRunning = true;
const hours = parseInt(hoursInput.value, 10);
const minutes = parseInt(minutesInput.value, 10);
const seconds = parseInt(secondsInput.value, 10);
timeRemaining = (hours * 3600) + (minutes * 60) + seconds;
timerInterval = setInterval(() => {
if (timeRemaining > 0) {
timeRemaining--;
updateTimeDisplay();
} else {
clearInterval(timerInterval);
timerRunning = false;
startStopButton.innerHTML = '<span class="material-icons">play_arrow</span>開始';
}
}, 1000);
startStopButton.innerHTML = '<span class="material-icons">pause</span>停止';
}
function stopTimer() {
clearInterval(timerInterval);
timerRunning = false;
startStopButton.innerHTML = '<span class="material-icons">play_arrow</span>開始';
}
function toggleTimer() {
if (timerRunning) {
stopTimer();
} else {
startTimer();
}
}
function resetTimer() {
stopTimer();
timeRemaining = 0;
updateTimeDisplay();
}
startStopButton.addEventListener('click', toggleTimer);
resetButton.addEventListener('click', resetTimer);
[hoursInput, minutesInput, secondsInput].forEach(input => {
input.addEventListener('input', () => {
if (!timerRunning) {
const hours = parseInt(hoursInput.value, 10) || 0;
const minutes = parseInt(minutesInput.value, 10) || 0;
const seconds = parseInt(secondsInput.value, 10) || 0;
timeRemaining = (hours * 3600) + (minutes * 60) + seconds;
}
});
});
updateTimeDisplay();
</script>
</body>
</html>