5 { 'running': false, 'elapsed': 0, 'origin': undefined, 'id': 'clock' },
6 { 'running': false, 'elapsed': 0, 'origin': undefined, 'id': 'clock2' }
9 let clock_visible = false;
10 let comment_visible = false;
11 let lowerthird_visible = false;
12 let clock_limit = 30 * 60;
19 document.getElementById('team1').innerHTML = state['team1'];
20 document.getElementById('team2').innerHTML = state['team2'];
22 let sheets = { 'A': state['team1'], 'B': state['team2'] };
28 document.getElementById('score2_team1').innerHTML = state['team1'];
29 document.getElementById('score2_team2').innerHTML = state['team2'];
34 document.getElementById('team1color').style.backgroundColor = state['team1color'];
35 document.getElementById('team2color').style.backgroundColor = state['team2color'];
40 scoreA = state['score1'];
41 scoreB = state['score2'];
47 scoreA = state['score1'];
48 scoreB = state['score2'];
49 document.getElementById('score2_score').innerHTML = scoreA + " – " + scoreB;
52 function startclock(num)
54 if (!clocks[num].running) {
55 clocks[num].origin = Date.now();
56 clocks[num].running = true;
63 function stopclock(num)
65 if (!clocks[num].running) return;
66 clocks[num].elapsed = time_elapsed(num);
67 clocks[num].origin = Date.now();
68 clocks[num].running = false;
71 function setclock(num, amount)
73 clocks[num].elapsed = amount;
74 clocks[num].origin = Date.now();
78 function setclockfromstate()
80 let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
84 // No setclock2fromstate.
86 function adjustclockfromstate(num)
88 let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
89 let elapsed = time_elapsed_raw(num);
90 if (Math.abs(amount - elapsed) >= 2.0) {
91 setclock(num, amount);
95 function setclocklimitfromstate()
97 let amount = parseInt(state['clock_limit_min']) * 60 + parseInt(state['clock_limit_sec']);
103 if (clock_visible) return;
104 let clockbug = document.getElementById('clockbug');
105 clockbug.className = 'clockbug clockbug-animate-in';
106 clock_visible = true;
111 if (!clock_visible) return;
112 let clockbug = document.getElementById('clockbug');
113 clockbug.className = 'clockbug clockbug-animate-out';
114 clock_visible = false;
117 function setcomment()
119 document.getElementById('comment').innerHTML = state['comment'];
122 function showcomment()
124 if (comment_visible) return;
125 let commentbug = document.getElementById('commentbug');
126 commentbug.className = 'commentbug commentbug-animate-in';
127 comment_visible = true;
130 function hidecomment()
132 if (!comment_visible) return;
133 let commentbug = document.getElementById('commentbug');
134 commentbug.className = 'commentbug commentbug-animate-out';
135 comment_visible = false;
138 function showlowerthird()
140 if (lowerthird_visible) return;
142 document.getElementById('lowerthird-headline').className = 'lowerthird-headline lowerthird-headline-animate-in';
143 document.getElementById('lowerthird-headline-content').className = 'lowerthird-headline-content lowerthird-headline-content-animate-in';
144 document.getElementById('lowerthird-subheading').className = 'lowerthird-subheading lowerthird-subheading-animate-in';
145 document.getElementById('lowerthird-subheading-content').className = 'lowerthird-subheading-content lowerthird-subheading-content-animate-in';
146 document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-in';
147 document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-in';
148 lowerthird_visible = true;
151 function setandshowlowerthird()
153 document.getElementById('lowerthird-headline-content').innerHTML = state['text1'];
154 document.getElementById('lowerthird-subheading-content').innerHTML = state['text2'];
155 let img = document.getElementById('lowerthird-img');
156 if (state['image'] === undefined) {
157 img.style.display = 'none';
159 img.src = state['image'];
160 img.style.display = 'inline';
165 function hidelowerthird()
167 if (!lowerthird_visible) return;
168 document.getElementById('lowerthird-headline').className = 'lowerthird-headline lowerthird-headline-hidden lowerthird-headline-animate-out';
169 document.getElementById('lowerthird-headline-content').className = 'lowerthird-headline-content lowerthird-headline-content-animate-out';
170 document.getElementById('lowerthird-subheading').className = 'lowerthird-subheading lowerthird-subheading-animate-out';
171 document.getElementById('lowerthird-subheading-content').className = 'lowerthird-subheading-content lowerthird-subheading-content-animate-out';
172 document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-out';
173 document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-out';
174 lowerthird_visible = false;
177 function time_elapsed_raw(num)
179 let elapsed = (Date.now() - clocks[num].origin) * 1e-3;
180 if (clocks[num].elapsed + elapsed >= clock_limit) {
181 console.log("limit for", num);
183 clocks[num].elapsed = clock_limit;
184 clocks[num].origin = Date.now();
185 clocks[num].running = false;
187 if (state['autocomment_on_clock_limit'] == '1' && !comment_visible) {
188 state['comment'] = state['autocomment'];
196 return clocks[num].elapsed + elapsed;
199 function time_elapsed(num)
201 return Math.floor(time_elapsed_raw(num));
204 function update_given_clock(elapsed, id)
206 let min = Math.floor(elapsed / 60);
207 let sec = elapsed % 60;
209 if (sec < 10) sec = "0" + sec;
210 let text = min + ":" + sec;
212 if (ultimateconfig['exohack']) {
213 // This is a hack around the fact that Exo has variable-width numerals.
214 // It doesn't look fantastic, but for the clock, it's better not to have
215 // the text jumping around.
217 for (let i = 0; i < text.length; ++i) {
218 if (text.charAt(i) === ':') {
221 html += "<div style='display: inline-block; width: 15px'>" + text.charAt(i) + "</div>";
224 document.getElementById(id).innerHTML = html;
226 document.getElementById(id).innerHTML = text;
230 function update_clock(num)
232 update_given_clock(time_elapsed(num), clocks[num].id);
249 if (scoreA > 0) --scoreA;
255 if (scoreB > 0) --scoreB;
259 function resetscore()
265 function update_score()
267 document.getElementById('score').innerHTML = scoreA + " – " + scoreB;
270 /* called by the Nageru theme only */
273 document.getElementById('manualcontrols').style.display = 'none';
274 document.getElementById('area').style.display = 'none';
279 console.log('[[[' + v + ']]]');
280 let j = JSON.parse(v);
281 for(let key in j) state[key] = j[key];
284 setInterval(function() {
285 for (let i = 0; i < num_clocks; ++i) {
286 if (clocks[i].running) {
296 let websocket = null;
300 console.log("Connecting...");
304 websocket = new WebSocket("ws://127.0.0.1:5250/");
305 websocket.onopen = function(evt) {
306 console.log("Connected to client.");
308 websocket.onclose = function(evt) {
309 console.log("Disconnected from client.");
310 setTimeout(open_ws, 100);
312 websocket.onmessage = function(evt) {
314 let m = msg.match(/^update (.*)/);
318 m = msg.match(/^eval (.*)/);
323 websocket.onerror = function(evt) {
324 console.log('Error: ' + evt.data);
326 } catch (exception) {
327 console.log('Error: ' + exception);
328 setTimeout(open_ws, 100);