-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
177 lines (153 loc) · 5 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
let countdownMinutes = 5;
let countdownSeconds = 0;
let countDownOn = false;
let timeInSeconds = 0;
let timeout;
let roundsTime = [];
let imageUrls = [];
let modalOpen = false;
window.addEventListener("keydown", (event) => {
if (modalOpen && event.key === 'Escape') {
closeModal();
}
})
function loadFile(event, competitor) {
let output = document.getElementById(competitor);
output.src = URL.createObjectURL(event.target.files[0]);
imageUrls.push(output.src);
// output.onload = function () {
// URL.revokeObjectURL(output.src)
// }
}
function refreshText(id, value) {
console.log(id, value);
let text = document.getElementById(id);
text.innerText = value;
}
function changeCountdownValues() {
countDownOn = false;
countdownMinutes = document.getElementById('minute-input').value;
countdownSeconds = document.getElementById('seconds-input').value;
updateCountdownString();
}
function updateCountdownString() {
const countdown = document.getElementById('countdown-string');
let countdownString = '' + addZeroIfNeeded(countdownMinutes) + ':' + addZeroIfNeeded(countdownSeconds);
countdown.innerText = countdownString;
}
function addZeroIfNeeded(value) {
if (value < 10) {
return '0' + value;
}
return value;
}
function calculateTimeFromSeconds() {
countdownMinutes = Math.floor(timeInSeconds / 60);
countdownSeconds = timeInSeconds - (countdownMinutes * 60);
}
function startCountDown() {
if (!countDownOn) {
countdownMinutes = parseInt(countdownMinutes, 10);
countdownSeconds = parseInt(countdownSeconds, 10);
timeInSeconds = (countdownMinutes * 60) + countdownSeconds;
timeInSeconds++;
countDownOn = true;
timeCount();
}
}
function timeCount() {
timeInSeconds--;
calculateTimeFromSeconds();
updateCountdownString();
if (timeInSeconds != 0) {
if (countDownOn) {
timeout = setTimeout(timeCount, 1000);
}
} else {
countDownOn = false;
}
}
function stopCountDown() {
if (countDownOn) {
clearTimeout(timeout);
countDownOn = false;
}
}
function resetCountDown() {
if (countDownOn) {
clearTimeout(timeout);
countDownOn = false;
}
changeCountdownValues();
}
function resetSettings() {
const inputs = document.getElementsByTagName("input");
for (const [key, entry] of Object.entries(inputs)) {
entry.value = '';
}
let comp1 = document.getElementById(Competitors.COMPETITOR1);
let comp2 = document.getElementById(Competitors.COMPETITOR2);
comp1.src = 'assets/no_image.png';
comp2.src = 'assets/no_image.png';
refreshText(Texts.COMPETITOR1_NAME, 'Competitor1');
refreshText(Texts.COMPETITOR2_NAME, 'Competitor2');
refreshText(Texts.COMPETITOR1_TEAM, 'Team');
refreshText(Texts.COMPETITOR2_TEAM, 'Team');
imageUrls.forEach(url => {
URL.revokeObjectURL(url);
})
}
function closeModal() {
const winnerOverlay = document.getElementById('winner-overlay');
winnerOverlay.style.opacity = 0;
setTimeout(() => {
winnerOverlay.style.visibility = 'hidden';
modalOpen = false;
}, 500);
const winnerButtons = document.getElementsByClassName('winner-button');
for (const [key, entry] of Object.entries(winnerButtons)) {
entry.style.opacity = 1;
entry.style.cursor = 'pointer';
}
}
function openModal() {
const winnerOverlay = document.getElementById('winner-overlay');
winnerOverlay.style.visibility = 'visible';
winnerOverlay.style.opacity = 1;
const winnerButtons = document.getElementsByClassName('winner-button');
for (const [key, entry] of Object.entries(winnerButtons)) {
entry.style.opacity = 0;
entry.style.cursor = 'default';
}
modalOpen = true;
}
function showWinner(competitor) {
const picture = document.getElementById(competitor);
const teamId = competitor === Competitors.COMPETITOR1 ? Texts.COMPETITOR1_TEAM : Texts.COMPETITOR2_TEAM;
const nameId = competitor === Competitors.COMPETITOR1 ? Texts.COMPETITOR1_NAME : Texts.COMPETITOR2_NAME;
const team = document.getElementById(teamId);
const name = document.getElementById(nameId);
const winnerPicture = document.getElementById('winner-image');
winnerPicture.src = picture.src;
console.log('pic src', picture.src);
refreshText('winner-name', name.innerText);
refreshText('winner-team', team.innerText);
const color = document.getElementById('winner-color');
const red = '#ce1919';
const blue = '#1919ce';
color.style.background = competitor === Competitors.COMPETITOR1 ? red : blue;
openModal();
}
function stopPropagationOnClick(event) {
event.stopPropagation()
}
const Competitors = {
COMPETITOR1: 'competitor1',
COMPETITOR2: 'competitor2',
};
const Texts = {
COMPETITOR1_NAME: 'competitor1-name',
COMPETITOR2_NAME: 'competitor2-name',
COMPETITOR1_TEAM: 'competitor1-team',
COMPETITOR2_TEAM: 'competitor2-team',
}