-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPLL.js
More file actions
414 lines (382 loc) · 12.6 KB
/
PLL.js
File metadata and controls
414 lines (382 loc) · 12.6 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
const openModalButtons = document.querySelectorAll('[data-modal-target]')
const closeModalButtons = document.querySelectorAll('[data-close-button]')
const overlay = document.getElementById('overlay')
const openModalButtonsStats = document.querySelectorAll('[data-modal-target-stats]')
const closeModalButtonsStats = document.querySelectorAll('[data-close-button-stats]')
const overlayStats = document.getElementById('overlayStats')
var checkedBoxes = [];
var count = 0;
var timeStats = [];
openModalButtons.forEach(button => {
button.addEventListener('click', () => {
const modal = document.querySelector(button.dataset.modalTarget)
openModal(modal)
})
})
overlay.addEventListener('click', () => {
const modals = document.querySelectorAll('.cases.active')
modals.forEach(modal => {
closeModal(modal)
})
})
closeModalButtons.forEach(button => {
button.addEventListener('click', () => {
const modal = button.closest('.cases')
closeModal(modal)
})
})
function openModal(modal) {
if (modal == null) return
modal.classList.add('active')
overlay.classList.add('active')
}
function closeModal(modal) {
if (modal == null) return
modal.classList.remove('active')
overlay.classList.remove('active')
checkedBoxes = getCheckedBoxes("casesChosen");
count = 0;
changeInfo(checkedBoxes);
onOrOff = 'reset';
startStop();
}
openModalButtonsStats.forEach(button => {
button.addEventListener('click', () => {
const modal = document.querySelector(button.dataset.modalTargetStats)
openModalStats(modal)
})
})
overlayStats.addEventListener('click', () => {
const modals = document.querySelectorAll('.stats.active')
modals.forEach(modal => {
closeModalStats(modal)
})
})
closeModalButtonsStats.forEach(button => {
button.addEventListener('click', () => {
const modal = button.closest('.stats')
closeModalStats(modal)
})
})
function openModalStats(modal) {
if (modal == null) return
modal.classList.add('active')
overlayStats.classList.add('active')
}
function closeModalStats(modal) {
if (modal == null) return
modal.classList.remove('active')
overlayStats.classList.remove('active')
}
// Pass the checkbox name to the function
function getCheckedBoxes(chkboxName) {
var checkboxes = document.getElementsByName(chkboxName);
var checkboxesChecked = [];
// loop over them all
for (var i=0; i<checkboxes.length; i++) {
// And stick the checked ones onto an array...
if (checkboxes[i].checked) {
checkboxesChecked.push(checkboxes[i]);
}
}
// Return the array if it is non-empty, or null
return checkboxesChecked.length > 0 ? checkboxesChecked : null;
}
function changeInfo(boxesCheck) {
if (boxesCheck == null) {
document.getElementById('centralDisplay').style.display = 'none';
document.getElementById('tempCentral').style.display = 'block';
} else if (boxesCheck.length > 0) {
document.getElementById('centralDisplay').style.display = 'block';
document.getElementById('tempCentral').style.display = 'none';
if (boxesCheck[count] == document.getElementById('caseF2l1')) {
document.getElementById("scramble").innerHTML = "Scramble: F' U2 L' U' L2 F L'";
document.getElementById("mainImage").src="images/casef2l1.png";
document.getElementById("solutionsF2l").innerHTML = "Solution: (R U' R') U (R U2 R') U (R U' R')";
} else if (boxesCheck[count] == document.getElementById('caseF2l2')) {
document.getElementById("scramble").innerHTML = "Scramble: R U' R2 U R";
document.getElementById("mainImage").src="images/casef2l2.png";
document.getElementById("solutionsF2l").innerHTML = "Solution: R' U' R2 U R'";
} else if (boxesCheck[count] == document.getElementById('caseF2l3')) {
document.getElementById("scramble").innerHTML = "Scramble: R U' R2 U R";
document.getElementById("mainImage").src="images/casef2l3.png";
document.getElementById("solutionsF2l").innerHTML = "Solution: R' U' R2 U R'";
}
}
}
function changeNextCase() {
if (document.getElementById('nextCaseF2l').checked) {
document.getElementById('nextCase').style.display = 'none';
} else {
document.getElementById('nextCase').style.display = 'block';
}
}
function showSolution() {
if (document.getElementById('showSolutionsF2l').checked) {
document.getElementById('solutionsF2l').style.display = 'block';
} else {
document.getElementById('solutionsF2l').style.display = 'none';
}
}
function moveNextCase() {
if (document.getElementById('randomizeF2l').checked) {
count = Math.floor(Math.random() * checkedBoxes.length);
changeInfo(checkedBoxes);
} else if (count == (checkedBoxes.length - 1)) {
count = 0;
changeInfo(checkedBoxes);
} else {
count++;
changeInfo(checkedBoxes);
}
onOrOff = 'reset';
startStop();
}
function best() {
var bestMin = timeStats[0][0];
var bestSec = timeStats[0][1];
var bestMil = timeStats[0][2];
for (var i = 0; i < timeStats.length; i++) {
if (timeStats[i][0] < bestMin){
bestMin = timeStats[i][0];
}
}
for (var i = 0; i < timeStats.length; i++) {
if (timeStats[i][0] == bestMin) {
if (timeStats[i][1] < bestSec) {
bestSec = timeStats[i][1];
}
}
}
for (var i = 0; i < timeStats.length; i++) {
if (timeStats[i][0] == bestMin) {
if (timeStats[i][1] == bestSec) {
if (timeStats[i][2] < bestMil) {
bestMil = timeStats[i][2];
}
}
}
}
if (bestMin.toString().length == 1) {
bestMin = '0' + bestMin;
}
if (bestSec.toString().length == 1) {
bestSec = '0' + bestSec;
}
if (bestMil.toString().length == 1) {
bestMil = '0' + bestMil;
}
document.getElementById('best').innerHTML = 'Best: ' + bestMin + ':' + bestSec + ':' + bestMil;
}
function worst() {
var worstMin = 0;
var worstSec = 0;
var worstMil = 0;
for (var i = 0; i < timeStats.length; i++) {
if (timeStats[i][0] > worstMin){
worstMin = timeStats[i][0];
}
}
for (var i = 0; i < timeStats.length; i++) {
if (timeStats[i][0] == worstMin) {
if (timeStats[i][1] > worstSec) {
worstSec = timeStats[i][1];
}
}
}
for (var i = 0; i < timeStats.length; i++) {
if (timeStats[i][0] == worstMin) {
if (timeStats[i][1] == worstSec) {
if (timeStats[i][2] > worstMil) {
worstMil = timeStats[i][2];
}
}
}
}
if (worstMin.toString().length == 1) {
worstMin = '0' + worstMin;
}
if (worstSec.toString().length == 1) {
worstSec = '0' + worstSec;
}
if (worstMil.toString().length == 1) {
worstMil = '0' + worstMil;
}
document.getElementById('worst').innerHTML = 'Worst: ' + worstMin + ':' + worstSec + ':' + worstMil;
}
function average() {
var temp = 0;
for (var i = 0; i < timeStats.length; i++) {
temp += (timeStats[i][0] * 6000);
temp += (timeStats[i][1] * 100);
temp += (timeStats[i][2]);
}
temp = temp / timeStats.length;
var tempMin = Math.floor(temp / 6000);
temp -= tempMin * 6000;
var tempSec = Math.floor(temp / 100);
temp -= tempSec * 100;
temp = Math.round(temp);
if (tempMin.toString().length == 1) {
tempMin = '0' + tempMin;
}
if (tempSec.toString().length == 1) {
tempSec = '0' + tempSec;
}
if (temp.toString().length == 1) {
temp = '0' + temp;
}
document.getElementById('average').innerHTML = 'Average: ' + tempMin + ':' + tempSec + ':' + temp;
}
function median() {
var tempMin = 0;
var tempSec = 0;
var tempMil = 0;
if (timeStats.length % 2 == 0) {
tempMin += timeStats[timeStats.length / 2][0];
tempSec += timeStats[timeStats.length / 2][1];
tempMil += timeStats[timeStats.length / 2][2];
tempMin += timeStats[(timeStats.length / 2) - 1][0];
tempSec += timeStats[(timeStats.length / 2) - 1][1];
tempMil += timeStats[(timeStats.length / 2) - 1][2];
tempMin = Math.round(tempMin / 2);
tempSec = Math.round(tempSec / 2);
tempMil = Math.round(tempMil / 2);
document.getElementById('median').innerHTML = 'Median: ' + tempMin + ':' + tempSec + ':' + tempMil;
} else {
}
}
function statistics(mil, sec, min) {
var newTime = [parseInt(min), parseInt(sec), parseInt(mil)];
timeStats.push(newTime);
average();
best();
worst();
median();
}
function times(mil, sec, min) {
var appendage = min + ":" + sec + ":" + mil;
var time = document.createElement('p');
time.innerHTML = appendage;
var trTemp = document.createElement('tr');
var thTemp1 = document.createElement('th');
var thTemp2 = document.createElement('th');
var btnTemp = document.createElement('button');
btnTemp.className = 'closeTime';
btnTemp.onclick = function() {
document.getElementById('times').removeChild(this.parentElement.parentElement);
};
btnTemp.innerHTML = '×';
thTemp1.style.fontSize = '3vh';
btnTemp.style.fontSize = '4vh';
btnTemp.style.border = 'none';
btnTemp.style.background = 'none';
thTemp1.appendChild(time);
thTemp2.appendChild(btnTemp);
trTemp.appendChild(thTemp1);
trTemp.appendChild(thTemp2);
document.getElementById('times').insertBefore(trTemp, document.getElementById('times').firstChild);
}
//Define vars to hold time values
let seconds = 0;
let minutes = 0;
let hours = 0;
//Define vars to hold "display" value
let displaySeconds = 0;
let displayMinutes = 0;
let displayHours = 0;
//Define var to hold setInterval() function
let interval = null;
//Define var to hold stopwatch status
let onOrOff = "stopped";
//Stopwatch function (logic to determine when to increment next value, etc.)
function stopWatch() {
seconds++;
//Logic to determine when to increment next value
if (seconds / 100 === 1) {
seconds = 0;
minutes++;
if (minutes / 60 === 1) {
minutes = 0;
hours++;
}
}
//If seconds/minutes/hours are only one digit, add a leading 0 to the value
if (seconds < 10) {
displaySeconds = "0" + seconds.toString();
} else {
displaySeconds = seconds;
}
if (minutes < 10) {
displayMinutes = "0" + minutes.toString();
} else {
displayMinutes = minutes;
}
if (hours < 10) {
displayHours = "0" + hours.toString();
} else {
displayHours = hours;
}
//Display updated time values to user
document.getElementById("mil").innerHTML = displaySeconds;
document.getElementById("sec").innerHTML = displayMinutes;
document.getElementById("min").innerHTML = displayHours;
}
function startStop() {
if (onOrOff === "stopped") {
//Start the stopwatch (by calling the setInterval() function)
interval = window.setInterval(stopWatch, 10);
onOrOff = "started";
} else if (onOrOff === 'started') {
window.clearInterval(interval);
onOrOff = "reset";
times(document.getElementById('mil').innerHTML, document.getElementById('sec').innerHTML, document.getElementById('min').innerHTML);
statistics(document.getElementById('mil').innerHTML, document.getElementById('sec').innerHTML, document.getElementById('min').innerHTML);
} else {
document.getElementById("mil").innerHTML = '00';
document.getElementById("sec").innerHTML = '00';
document.getElementById("min").innerHTML = '00';
seconds = 0;
minutes = 0;
hours = 0;
onOrOff = 'stopped';
window.clearInterval(interval);
if (document.getElementById('randomizeF2l').checked) {
count = Math.floor(Math.random() * checkedBoxes.length);
changeInfo(checkedBoxes);
} else if (document.getElementById('nextCaseF2l').checked) {
if (count == (checkedBoxes.length - 1)) {
count = 0;
changeInfo(checkedBoxes);
} else {
count++;
changeInfo(checkedBoxes);
}
}
}
}
document.body.onkeyup = function(e){ if(e.keyCode == 32){
if (checkedBoxes.length > 0) {
document.getElementById('mil').style.color = "black";
document.getElementById('sec').style.color = "black";
document.getElementById('min').style.color = "black";
document.getElementById('colon').style.color = "black";
document.getElementById('colon1').style.color = "black";
startStop();
}
}};
document.body.onkeydown = function(e){ if(e.keyCode == 32){
if (checkedBoxes.length > 0) {
if (onOrOff == "stopped") {
document.getElementById('mil').style.color = "#00ffb7";
document.getElementById('sec').style.color = "#00ffb7";
document.getElementById('min').style.color = "#00ffb7";
document.getElementById('colon').style.color = "#00ffb7";
document.getElementById('colon1').style.color = "#00ffb7";
}
}
}};
cases.addEventListener("transitionend", function(){
cases.active.style.transform = '';
}, false);
//document.getElementById("mainImage").src="../template/save.png";