-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
180 lines (132 loc) · 5.08 KB
/
main.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
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
// ランダマイザー
const spin = [
"R","R2","R'",
"U","U2","U'",
"L","L2","L'",
"B","B2","B'",
"D","D2","D'",
"F","F2","F'",
"M","M2","M'",
];
document.getElementsByTagName("button")[0].addEventListener("click" , ()=> {
for(i = spin.length - 1; i > 1; i--) {
let j = Math.floor(Math.random() * (i + 1));
let tmp = spin[i];
spin[i] = spin[j];
spin[j] = tmp;
};
document.getElementById("randomize").textContent = spin;
});
// console.log(document.getElementById("randomize").textContent.length); ダメでした
// フィッシャー–イェーツのシャッフル
// for(i = array.length - 1; i > 1; i--) {
// var j = Math.floor(Math.random() * (i + 1));
// var tmp = array[i];
// array[i] = array[j];
// array[j] = tmp;
// };
// document.getElementById("randomize").textContent = array;
// タイマー部分
// 以下丸パクリ
// 性質上、何時間は不要なので、時間関連は削除。
const timeElement = document.getElementById('time');
const start = document.getElementById('start');
const stop = document.getElementById('stop');
const reset = document.getElementById('reset');
const record = document.getElementById("record");
// console.log(document.getElementById("record").innerText);
// 経過時間のミリ秒
let elapsed = 0;
let intervalId = null;
function updateTime() {
const ms = elapsed % 1000;
const s = Math.floor(elapsed / 1000) % 60;
const m = Math.floor(elapsed / (1000*60)) % 60;
const h = Math.floor(elapsed / (1000*60*60));
const msStr = ms.toString().padStart(3, '0');
const sStr = s.toString().padStart(2, '0');
const mStr = m.toString().padStart(2, '0');
const hStr = h.toString().padStart(2, '0');
timeElement.innerHTML = `${mStr}:${sStr}.${msStr}`;
}
start.addEventListener('click', function(e) {
if (intervalId !== null) { return; }
let pre = new Date();
intervalId = setInterval(function() {
const now = new Date();
elapsed += now - pre;
pre = now;
updateTime();
}, 10);
});
// stop.addEventListener('click', function(e) {
// const ms = elapsed % 1000;
// const s = Math.floor(elapsed / 1000) % 60;
// const m = Math.floor(elapsed / (1000*60)) % 60;
// const h = Math.floor(elapsed / (1000*60*60));
// const msStr = ms.toString().padStart(3, '0');
// const sStr = s.toString().padStart(2, '0');
// const mStr = m.toString().padStart(2, '0');
// const hStr = h.toString().padStart(2, '0');
// // function updateTime下で定数指定をしている為、同じように表示するにはここにも必要。
// //
// clearInterval(intervalId);
// intervalId = null;
// // record1.innerHTML = `${mStr}:${sStr}.${msStr}`;
// });
// stop関連
let not = 0;
stop.addEventListener("click", function () {
const ms = elapsed % 1000;
const s = Math.floor(elapsed / 1000) % 60;
const m = Math.floor(elapsed / (1000*60)) % 60;
const h = Math.floor(elapsed / (1000*60*60));
const msStr = ms.toString().padStart(3, '0');
const sStr = s.toString().padStart(2, '0');
const mStr = m.toString().padStart(2, '0');
const hStr = h.toString().padStart(2, '0');
not++;
if (not == 1) {
record1.innerHTML = `${mStr}:${sStr}.${msStr}`;
elapsed1 = elapsed;
} else if (not == 2) {
record2.innerHTML = `${mStr}:${sStr}.${msStr}`;
elapsed2 = elapsed;
} else if (not == 3) {
record3.innerHTML = `${mStr}:${sStr}.${msStr}`;
elapsed3 = elapsed;
} else if (not == 4) {
record4.innerHTML = `${mStr}:${sStr}.${msStr}`;
elapsed4 = elapsed;
} else if (not == 5) {
record5.innerHTML = `${mStr}:${sStr}.${msStr}`;
elapsed5 = elapsed;
averege = [elapsed1 + elapsed2 + elapsed3 + elapsed4 + elapsed5]/5;
const a_ms = elapsed % 1000;
const a_s = Math.floor(averege / 1000) % 60;
const a_m = Math.floor(averege / (1000*60)) % 60;
// const a_h = Math.floor(averege / (1000*60*60));
const a_msStr = a_ms.toString().padStart(3, '0');
const a_sStr = a_s.toString().padStart(2, '0');
const a_mStr = a_m.toString().padStart(2, '0');
// const a_hStr = h.toString().padStart(2, '0');
avg.innerHTML = "5回平均" + `${mStr}:${sStr}.${msStr}`;
};
clearInterval(intervalId);
intervalId = null;
elapsed = 0;
updateTime();
});
// reset関連
reset.addEventListener('click', function(e) {
// let score = ["record1","record2","record3","record4","record5"];
// scoreIndex = 0;
// scoreLength = score.length;
// // let res = document.getElementById("scoreLength");
document.getElementById("record1").textContent = "00:00.000";
document.getElementById("record2").textContent = "00:00.000";
document.getElementById("record3").textContent = "00:00.000";
document.getElementById("record4").textContent = "00:00.000";
document.getElementById("record5").textContent = "00:00.000";
document.getElementById("avg").textContent = "00:00.000";
});