3 let clock_running = false;
4 let clock2_running = false;
5 let clock_visible = false;
6 let scorebug2_visible = false;
7 let comment_visible = false;
8 let lowerthird_visible = false;
10 let clock2_elapsed = 0;
11 let clock_limit = 30 * 60;
20 document.getElementById('team1').innerHTML = state['team1'];
21 document.getElementById('team2').innerHTML = state['team2'];
23 let sheets = { 'A': state['team1'], 'B': state['team2'] };
29 document.getElementById('score2_team1').innerHTML = state['team1'];
30 document.getElementById('score2_team2').innerHTML = state['team2'];
35 document.getElementById('team1color').style.backgroundColor = state['team1color'];
36 document.getElementById('team2color').style.backgroundColor = state['team2color'];
41 scoreA = state['score1'];
42 scoreB = state['score2'];
48 scoreA = state['score1'];
49 scoreB = state['score2'];
50 document.getElementById('score2_score').innerHTML = scoreA + " – " + scoreB;
56 clock_origin = Date.now();
62 function startclock2()
64 if (!clock2_running) {
65 clock2_origin = Date.now();
66 clock2_running = true;
73 if (!clock_running) return;
74 clock_elapsed = time_elapsed();
75 clock_origin = Date.now();
76 clock_running = false;
81 if (!clock2_running) return;
82 clock2_elapsed = time2_elapsed();
83 clock2_origin = Date.now();
84 clock2_running = false;
87 function setclock(amount)
89 clock_elapsed = amount;
90 clock_origin = Date.now();
94 function setclock2(amount)
96 clock2_elapsed = amount;
97 clock2_origin = Date.now();
101 function setclockfromstate()
103 let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
107 // No setclock2fromstate.
109 function adjustclockfromstate()
111 let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
112 let elapsed = time_elapsed_raw();
113 if (Math.abs(amount - elapsed) >= 2.0) {
118 function adjustclock2fromstate()
120 let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
121 let elapsed = time_elapsed2_raw();
122 if (Math.abs(amount - elapsed) >= 2.0) {
127 function setclocklimitfromstate()
129 let amount = parseInt(state['clock_limit_min']) * 60 + parseInt(state['clock_limit_sec']);
130 clock_limit = amount;
135 if (clock_visible) return;
136 let clockbug = document.getElementById('clockbug');
137 clockbug.className = 'clockbug clockbug-animate-in';
138 clock_visible = true;
143 if (!clock_visible) return;
144 let clockbug = document.getElementById('clockbug');
145 clockbug.className = 'clockbug clockbug-animate-out';
146 clock_visible = false;
149 function setcomment()
151 document.getElementById('comment').innerHTML = state['comment'];
154 function showcomment()
156 if (comment_visible) return;
157 let commentbug = document.getElementById('commentbug');
158 commentbug.className = 'commentbug commentbug-animate-in';
159 comment_visible = true;
162 function hidecomment()
164 if (!comment_visible) return;
165 let commentbug = document.getElementById('commentbug');
166 commentbug.className = 'commentbug commentbug-animate-out';
167 comment_visible = false;
170 function showlowerthird()
172 if (lowerthird_visible) return;
174 document.getElementById('lowerthird-headline').className = 'lowerthird-headline lowerthird-headline-animate-in';
175 document.getElementById('lowerthird-headline-content').className = 'lowerthird-headline-content lowerthird-headline-content-animate-in';
176 document.getElementById('lowerthird-subheading').className = 'lowerthird-subheading lowerthird-subheading-animate-in';
177 document.getElementById('lowerthird-subheading-content').className = 'lowerthird-subheading-content lowerthird-subheading-content-animate-in';
178 document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-in';
179 document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-in';
180 lowerthird_visible = true;
183 function setandshowlowerthird()
185 document.getElementById('lowerthird-headline-content').innerHTML = state['text1'];
186 document.getElementById('lowerthird-subheading-content').innerHTML = state['text2'];
187 let img = document.getElementById('lowerthird-img');
188 if (state['image'] === undefined) {
189 img.style.display = 'none';
191 img.src = state['image'];
192 img.style.display = 'inline';
197 function hidelowerthird()
199 if (!lowerthird_visible) return;
200 document.getElementById('lowerthird-headline').className = 'lowerthird-headline lowerthird-headline-hidden lowerthird-headline-animate-out';
201 document.getElementById('lowerthird-headline-content').className = 'lowerthird-headline-content lowerthird-headline-content-animate-out';
202 document.getElementById('lowerthird-subheading').className = 'lowerthird-subheading lowerthird-subheading-animate-out';
203 document.getElementById('lowerthird-subheading-content').className = 'lowerthird-subheading-content lowerthird-subheading-content-animate-out';
204 document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-out';
205 document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-out';
206 lowerthird_visible = false;
209 function time_elapsed_raw()
211 let elapsed = (Date.now() - clock_origin) * 1e-3;
212 if (clock_elapsed + elapsed >= clock_limit) {
213 clock_elapsed = clock_limit;
214 clock_origin = Date.now();
215 clock_running = false;
217 if (state['autocomment_on_clock_limit'] == '1' && !comment_visible) {
218 state['comment'] = state['autocomment'];
225 return clock_elapsed + elapsed;
228 function time_elapsed2_raw()
230 let elapsed = (Date.now() - clock2_origin) * 1e-3;
231 if (clock2_elapsed + elapsed >= clock_limit) {
232 // No separate clock 2 limit.
235 return clock2_elapsed + elapsed;
238 function time_elapsed()
240 return Math.floor(time_elapsed_raw());
243 function time_elapsed2()
245 return Math.floor(time_elapsed2_raw());
248 function update_given_clock(elapsed, id)
250 let min = Math.floor(elapsed / 60);
251 let sec = elapsed % 60;
253 if (sec < 10) sec = "0" + sec;
254 let text = min + ":" + sec;
256 if (ultimateconfig['exohack']) {
257 // This is a hack around the fact that Exo has variable-width numerals.
258 // It doesn't look fantastic, but for the clock, it's better not to have
259 // the text jumping around.
261 for (let i = 0; i < text.length; ++i) {
262 if (text.charAt(i) === ':') {
265 html += "<div style='display: inline-block; width: 15px'>" + text.charAt(i) + "</div>";
268 document.getElementById(id).innerHTML = html;
270 document.getElementById(id).innerHTML = text;
274 function update_clock()
276 update_given_clock(time_elapsed(), 'clock');
279 function update_clock2()
281 update_given_clock(time_elapsed2(), 'clock2');
298 if (scoreA > 0) --scoreA;
304 if (scoreB > 0) --scoreB;
308 function resetscore()
314 function update_score()
316 document.getElementById('score').innerHTML = scoreA + " – " + scoreB;
319 /* called by the Nageru theme only */
322 document.getElementById('manualcontrols').style.display = 'none';
323 document.getElementById('area').style.display = 'none';
328 console.log('[[[' + v + ']]]');
329 let j = JSON.parse(v);
330 for(let key in j) state[key] = j[key];
333 setInterval(function() {
337 if (clock2_running) {
346 let websocket = null;
350 console.log("Connecting...");
354 websocket = new WebSocket("ws://127.0.0.1:5250/");
355 websocket.onopen = function(evt) {
356 console.log("Connected to client.");
358 websocket.onclose = function(evt) {
359 console.log("Disconnected from client.");
360 setTimeout(open_ws, 100);
362 websocket.onmessage = function(evt) {
364 let m = msg.match(/^update (.*)/);
368 m = msg.match(/^eval (.*)/);
373 websocket.onerror = function(evt) {
374 console.log('Error: ' + evt.data);
376 } catch (exception) {
377 console.log('Error: ' + exception);
378 setTimeout(open_ws, 100);