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_clock()
250 let elapsed = time_elapsed();
251 let min = Math.floor(elapsed / 60);
252 let sec = elapsed % 60;
254 if (sec < 10) sec = "0" + sec;
255 let text = min + ":" + sec;
258 // This is a hack around the fact that Exo has variable-width numerals.
259 // It doesn't look fantastic, but for the clock, it's better not to have
260 // the text jumping around.
262 for (let i = 0; i < text.length; ++i) {
263 if (text.charAt(i) === ':') {
266 html += "<div style='display: inline-block; width: 15px'>" + text.charAt(i) + "</div>";
269 document.getElementById('clock').innerHTML = html;
271 document.getElementById('clock').innerHTML = text;
275 function update_clock2()
277 let elapsed = time_elapsed2();
278 let min = Math.floor(elapsed / 60);
279 let sec = elapsed % 60;
281 if (sec < 10) sec = "0" + sec;
282 let text = min + ":" + sec;
284 document.getElementById('clock2').innerHTML = text;
301 if (scoreA > 0) --scoreA;
307 if (scoreB > 0) --scoreB;
311 function resetscore()
317 function update_score()
319 document.getElementById('score').innerHTML = scoreA + " – " + scoreB;
322 /* called by the Nageru theme only */
325 document.getElementById('manualcontrols').style.display = 'none';
326 document.getElementById('area').style.display = 'none';
331 console.log('[[[' + v + ']]]');
332 let j = JSON.parse(v);
333 for(let key in j) state[key] = j[key];
336 setInterval(function() {
340 if (clock2_running) {
349 let websocket = null;
353 console.log("Connecting...");
357 websocket = new WebSocket("ws://127.0.0.1:5250/");
358 websocket.onopen = function(evt) {
359 console.log("Connected to client.");
361 websocket.onclose = function(evt) {
362 console.log("Disconnected from client.");
363 setTimeout(open_ws, 100);
365 websocket.onmessage = function(evt) {
367 let m = msg.match(/^update (.*)/);
371 m = msg.match(/^eval (.*)/);
376 websocket.onerror = function(evt) {
377 console.log('Error: ' + evt.data);
379 } catch (exception) {
380 console.log('Error: ' + exception);
381 setTimeout(open_ws, 100);