-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
106 lines (81 loc) · 2.87 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
// ランダマイザー
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;
record.innerHTML = `${mStr}:${sStr}.${msStr}`;
});
reset.addEventListener('click', function(e) {
elapsed = 0;
updateTime();
});