-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (61 loc) · 2.25 KB
/
Copy pathscript.js
File metadata and controls
85 lines (61 loc) · 2.25 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
const config = document.querySelector('.config');
const configExist = document.querySelector('.dashboardExit');
const dashboard = document.querySelector('.dashboard');
const startButton = document.querySelector('#startButton');
const pickWindow = document.querySelector('.pickWindow');
const memberName = document.querySelector('.pickWindow .memberName');
const membersTable = document.querySelector('.membersTable tbody');
let candidates;
Array.prototype.randomize = function() {
return Math.floor(Math.random() * this.length);
}
function showMembersTable(event) {
dashboard.classList.add('show');
}
function hideMembersTable(event) {
dashboard.classList.remove('show');
}
function startPicking() {
pickWindow.classList.add('start');
}
config.addEventListener('click', showMembersTable)
configExist.addEventListener('click', hideMembersTable)
function updateCnadidates(candidateTableValue) {
const memberItem = document.createElement('tr');
const memberItemName = document.createElement('td');
memberItemName.textContent = candidateTableValue;
memberItem.appendChild(memberItemName);
membersTable.appendChild(memberItem);
}
function startRandomPick(clickEvent) {
if(pickWindow.classList.contains('start')) return;
startPicking();
let pick = setInterval(()=>{ memberName.textContent = candidates[candidates.randomize()] } , 30);
function startAndEndConfetti()
{
clearInterval(pick);
pickWindow.classList.remove('start');
confetti.start();
setTimeout(()=>{ confetti.stop() }, 2000)
}
setTimeout(startAndEndConfetti, 2000);
}
async function getMembers() {
function responseJsonForm(members) {
if(members.length === 0)
{
memberName.textContent = 'No member has been provided';
updateCnadidates('empty');
return;
}
candidates = members;
for(let member of members) updateCnadidates(member);
memberName.textContent = candidates[members.randomize()];
startButton.addEventListener('click', startRandomPick)
}
function fetchResponse(response) {
response.json().then(responseJsonForm);
}
await fetch('./members.json').then(fetchResponse);
}
window.onload = getMembers();