-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
104 lines (91 loc) · 3.35 KB
/
Copy pathindex.html
File metadata and controls
104 lines (91 loc) · 3.35 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>シンプルなタイマー</title>
<style>
body {
font-family: sans-serif;
text-align: center;
}
#timer {
font-size: 2em;
margin-bottom: 20px;
}
input[type="number"] {
width: 60px;
}
button {
padding: 10px 20px;
margin: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>シンプルなタイマー</h1>
<div id="timer">25:00</div>
<div>
<label for="studyTime">Study Time (分):</label>
<input type="number" id="studyTime" value="25" min="1">
</div>
<div>
<label for="breakTime">Short Break (分):</label>
<input type="number" id="breakTime" value="5" min="1">
</div>
<button id="startButton">スタート</button>
<button id="stopButton" disabled>ストップ</button>
<script>
// JavaScript コードはこの下に書きます
let timerDisplay = document.getElementById("timer");
let studyTimeInput = document.getElementById("studyTime");
let breakTimeInput = document.getElementById("breakTime");
let startButton = document.getElementById("startButton");
let stopButton = document.getElementById("stopButton");
let timerInterval;
let remainingTime;
let isStudyTime = true;
function updateDisplay() {
const minutes = Math.floor(remainingTime / 60);
const seconds = remainingTime % 60;
timerDisplay.textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
}
function startTimer() {
const studyMinutes = parseInt(studyTimeInput.value);
const breakMinutes = parseInt(breakTimeInput.value);
remainingTime = isStudyTime ? studyMinutes * 60 : breakMinutes * 60;
updateDisplay();
startButton.disabled = true;
stopButton.disabled = false;
timerInterval = setInterval(() => {
remainingTime--;
updateDisplay();
if (remainingTime <= 0) {
clearInterval(timerInterval);
if (isStudyTime) {
alert("Study Time 終了!休憩に入ります。");
isStudyTime = false;
} else {
alert("休憩終了!Study Time に戻ります。");
isStudyTime = true;
}
startTimer(); // 次のタイマーを開始
}
}, 1000); // 1000ミリ秒 (1秒) ごとに処理を実行
}
function stopTimer() {
clearInterval(timerInterval);
startButton.disabled = false;
stopButton.disabled = true;
}
startButton.addEventListener("click", startTimer);
stopButton.addEventListener("click", stopTimer);
// ページ読み込み時に初期表示
const initialStudyMinutes = parseInt(studyTimeInput.value);
remainingTime = initialStudyMinutes * 60;
updateDisplay();
</script>
</body>
</html>