5 { 'running': false, 'elapsed': 0, 'origin': undefined, 'id': 'clock' },
6 { 'running': false, 'elapsed': 0, 'origin': undefined, 'id': 'clock2' },
7 { 'running': false, 'elapsed': 0, 'origin': undefined, 'id': 'clock3' }
10 let clock_visible = false;
11 let comment_visible = false;
12 let lowerthird_visible = false;
13 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('score3_team1').innerHTML = state['team1'];
36 document.getElementById('score3_team2').innerHTML = state['team2'];
41 document.getElementById('team1color').style.backgroundColor = state['team1color'];
42 document.getElementById('team2color').style.backgroundColor = state['team2color'];
47 scoreA = state['score1'];
48 scoreB = state['score2'];
54 scoreA = state['score1'];
55 scoreB = state['score2'];
56 document.getElementById('score2_score').innerHTML = scoreA + " – " + scoreB;
61 scoreA = state['score1'];
62 scoreB = state['score2'];
63 document.getElementById('score3_score').innerHTML = scoreA + " – " + scoreB;
66 function startclock(num)
68 if (!clocks[num].running) {
69 clocks[num].origin = Date.now();
70 clocks[num].running = true;
77 function stopclock(num)
79 if (!clocks[num].running) return;
80 clocks[num].elapsed = time_elapsed(num);
81 clocks[num].origin = Date.now();
82 clocks[num].running = false;
85 function setclock(num, amount)
87 clocks[num].elapsed = amount;
88 clocks[num].origin = Date.now();
92 function setclockfromstate()
94 let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
98 // No setclock2fromstate.
100 function adjustclockfromstate(num)
102 let amount = parseInt(state['clock_min']) * 60 + parseInt(state['clock_sec']);
103 let elapsed = time_elapsed_raw(num);
104 if (Math.abs(amount - elapsed) >= 2.0) {
105 setclock(num, amount);
109 function setclocklimitfromstate()
111 let amount = parseInt(state['clock_limit_min']) * 60 + parseInt(state['clock_limit_sec']);
112 clock_limit = amount;
117 if (clock_visible) return;
118 let clockbug = document.getElementById('clockbug');
119 clockbug.className = 'clockbug clockbug-animate-in';
120 clock_visible = true;
125 if (!clock_visible) return;
126 let clockbug = document.getElementById('clockbug');
127 clockbug.className = 'clockbug clockbug-animate-out';
128 clock_visible = false;
131 function setcomment()
133 document.getElementById('comment').innerHTML = state['comment'];
136 function showcomment()
138 if (comment_visible) return;
139 let commentbug = document.getElementById('commentbug');
140 commentbug.className = 'commentbug commentbug-animate-in';
141 comment_visible = true;
144 function hidecomment()
146 if (!comment_visible) return;
147 let commentbug = document.getElementById('commentbug');
148 commentbug.className = 'commentbug commentbug-animate-out';
149 comment_visible = false;
152 function showlowerthird()
154 if (lowerthird_visible) return;
156 document.getElementById('lowerthird-headline').className = 'lowerthird-headline lowerthird-headline-animate-in';
157 document.getElementById('lowerthird-headline-content').className = 'lowerthird-headline-content lowerthird-headline-content-animate-in';
158 document.getElementById('lowerthird-subheading').className = 'lowerthird-subheading lowerthird-subheading-animate-in';
159 document.getElementById('lowerthird-subheading-content').className = 'lowerthird-subheading-content lowerthird-subheading-content-animate-in';
160 document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-in';
161 document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-in';
162 lowerthird_visible = true;
165 function setandshowlowerthird()
167 document.getElementById('lowerthird-headline-content').innerHTML = state['text1'];
168 document.getElementById('lowerthird-subheading-content').innerHTML = state['text2'];
169 let img = document.getElementById('lowerthird-img');
170 if (state['image'] === undefined) {
171 img.style.display = 'none';
173 img.src = state['image'];
174 img.style.display = 'inline';
179 function hidelowerthird()
181 if (!lowerthird_visible) return;
182 document.getElementById('lowerthird-headline').className = 'lowerthird-headline lowerthird-headline-hidden lowerthird-headline-animate-out';
183 document.getElementById('lowerthird-headline-content').className = 'lowerthird-headline-content lowerthird-headline-content-animate-out';
184 document.getElementById('lowerthird-subheading').className = 'lowerthird-subheading lowerthird-subheading-animate-out';
185 document.getElementById('lowerthird-subheading-content').className = 'lowerthird-subheading-content lowerthird-subheading-content-animate-out';
186 document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-out';
187 document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-out';
188 lowerthird_visible = false;
191 function set_sound_shark_volume_db(volume_db)
193 let img = document.getElementById('lowerthird-img');
194 let should_enable = (volume_db > -40.0);
195 let currently_enabled = (img.style.display === 'inline' && img.src.match(/microphone\.png$/));
197 if (should_enable === currently_enabled) {
202 img.style.display = 'inline';
203 img.src = 'generic/microphone.png';
204 document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-in';
205 document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-in';
207 document.getElementById('lowerthird-picture').className = 'lowerthird-picture lowerthird-picture-animate-out';
208 document.getElementById('lowerthird-picture-content').className = 'lowerthird-picture-content lowerthird-picture-content-animate-out';
212 function time_elapsed_raw(num)
214 let elapsed = (Date.now() - clocks[num].origin) * 1e-3;
215 if (clocks[num].elapsed + elapsed >= clock_limit) {
216 console.log("limit for", num);
218 clocks[num].elapsed = clock_limit;
219 clocks[num].origin = Date.now();
220 clocks[num].running = false;
222 if (state['autocomment_on_clock_limit'] == '1' && !comment_visible) {
223 state['comment'] = state['autocomment'];
231 return clocks[num].elapsed + elapsed;
234 function time_elapsed(num)
236 return Math.floor(time_elapsed_raw(num));
239 function update_given_clock(elapsed, id)
241 let min = Math.floor(elapsed / 60);
242 let sec = elapsed % 60;
244 if (sec < 10) sec = "0" + sec;
245 let text = min + ":" + sec;
247 if (ultimateconfig['exohack']) {
248 // This is a hack around the fact that Exo has variable-width numerals.
249 // It doesn't look fantastic, but for the clock, it's better not to have
250 // the text jumping around.
252 for (let i = 0; i < text.length; ++i) {
253 if (text.charAt(i) === ':') {
256 html += "<div style='display: inline-block; width: 15px'>" + text.charAt(i) + "</div>";
259 document.getElementById(id).innerHTML = html;
261 document.getElementById(id).innerHTML = text;
265 function update_clock(num)
267 update_given_clock(time_elapsed(num), clocks[num].id);
284 if (scoreA > 0) --scoreA;
290 if (scoreB > 0) --scoreB;
294 function resetscore()
300 function update_score()
302 document.getElementById('score').innerHTML = scoreA + " – " + scoreB;
305 /* called by the Nageru theme only */
308 document.getElementById('manualcontrols').style.display = 'none';
309 document.getElementById('area').style.display = 'none';
314 console.log('[[[' + v + ']]]');
315 let j = JSON.parse(v);
316 for(let key in j) state[key] = j[key];
319 setInterval(function() {
320 for (let i = 0; i < num_clocks; ++i) {
321 if (clocks[i].running) {
331 let websocket = null;
335 console.log("Connecting...");
339 websocket = new WebSocket("ws://127.0.0.1:5250/");
340 websocket.onopen = function(evt) {
341 console.log("Connected to client.");
343 websocket.onclose = function(evt) {
344 console.log("Disconnected from client.");
345 setTimeout(open_ws, 100);
347 websocket.onmessage = function(evt) {
349 let m = msg.match(/^update (.*)/);
353 m = msg.match(/^eval (.*)/);
358 websocket.onerror = function(evt) {
359 console.log('Error: ' + evt.data);
361 } catch (exception) {
362 console.log('Error: ' + exception);
363 setTimeout(open_ws, 100);