@@ -207,13 +207,29 @@ function getSelectedTeams()
207207 return JSON . parse ( cookieVal ) ;
208208}
209209
210- function getScoreboard ( )
210+ function getScoreboards ( mobile )
211211{
212- var scoreboard = document . getElementsByClassName ( "scoreboard" ) ;
213- if ( scoreboard === null || scoreboard [ 0 ] === null || scoreboard [ 0 ] === undefined ) {
212+ const scoreboards = document . getElementsByClassName ( "scoreboard" ) ;
213+ if ( scoreboards === null || scoreboards [ 0 ] === null || scoreboards [ 0 ] === undefined ) {
214214 return null ;
215215 }
216- return scoreboard [ 0 ] . rows ;
216+ let scoreboardRows = { } ;
217+ const mobileScoreboardClass = 'mobile-scoreboard' ;
218+ const desktopScoreboardClass = 'desktop-scoreboard' ;
219+ for ( let i = 0 ; i < scoreboards . length ; i ++ ) {
220+ if ( scoreboards [ i ] . classList . contains ( mobileScoreboardClass ) ) {
221+ scoreboardRows . mobile = scoreboards [ i ] . rows ;
222+ } else if ( scoreboards [ i ] . classList . contains ( desktopScoreboardClass ) ) {
223+ scoreboardRows . desktop = scoreboards [ i ] . rows ;
224+ }
225+ }
226+ if ( mobile === undefined ) {
227+ return scoreboardRows ;
228+ } else if ( mobile ) {
229+ return scoreboardRows . mobile ;
230+ } else {
231+ return scoreboardRows . desktop ;
232+ }
217233}
218234
219235function getRank ( row )
@@ -226,7 +242,7 @@ function getHeartCol(row) {
226242 var td = null ;
227243 // search for td before the team name
228244 for ( var i = 1 ; i < 4 ; i ++ ) {
229- if ( tds [ i ] . className == "scoretn" ) {
245+ if ( tds [ i ] . classList . contains ( "scoretn" ) ) {
230246 td = tds [ i - 1 ] ;
231247 break ;
232248 }
@@ -249,16 +265,28 @@ function getTeamname(row)
249265 return row . getAttribute ( "data-team-id" ) ;
250266}
251267
252- function toggle ( id , show )
268+ function toggle ( id , show , mobile )
253269{
254- var scoreboard = getScoreboard ( ) ;
270+ var scoreboard = getScoreboards ( mobile ) ;
255271 if ( scoreboard === null ) return ;
256272
273+ // Filter out all rows that do not have a data-team-id attribute or have
274+ // the class `scoreheader`.
275+ // The mobile scoreboard has them, and we need to ignore them.
276+ scoreboard = Array . from ( scoreboard )
277+ . filter (
278+ row => row . getAttribute ( "data-team-id" )
279+ || row . classList . contains ( "scoreheader" )
280+ ) ;
281+
257282 var favTeams = getSelectedTeams ( ) ;
258283 // count visible favourite teams (if filtered)
259284 var visCnt = 0 ;
260285 for ( var i = 0 ; i < favTeams . length ; i ++ ) {
261286 for ( var j = 0 ; j < scoreboard . length ; j ++ ) {
287+ if ( ! scoreboard [ j ] . getAttribute ( "data-team-id" ) ) {
288+ continue ;
289+ }
262290 var scoreTeamname = getTeamname ( scoreboard [ j ] ) ;
263291 if ( scoreTeamname === null ) {
264292 continue ;
@@ -297,69 +325,99 @@ function toggle(id, show)
297325 } ) ;
298326}
299327
300- function addHeart ( rank , row , id , isFav )
328+ function addHeart ( rank , row , id , isFav , mobile )
301329{
302330 var heartCol = getHeartCol ( row ) ;
303331 var iconClass = isFav ? "fas fa-heart" : "far fa-heart" ;
304- return heartCol . innerHTML + "<span class=\"heart " + iconClass + "\" onclick=\"toggle(" + id + "," + ( isFav ? "false" : "true" ) + ")\"></span>" ;
332+ return heartCol . innerHTML + "<span class=\"heart " + iconClass + "\" onclick=\"toggle(" + id + "," + ( isFav ? "false" : "true" ) + "," + mobile + " )\"></span>";
305333}
306334
307335function initFavouriteTeams ( )
308336{
309- var scoreboard = getScoreboard ( ) ;
310- if ( scoreboard === null ) {
337+ const scoreboards = getScoreboards ( ) ;
338+ if ( scoreboards === null ) {
311339 return ;
312340 }
313341
314342 var favTeams = getSelectedTeams ( ) ;
315- var toAdd = new Array ( ) ;
316- var cntFound = 0 ;
317- var lastRank = 0 ;
318- for ( var j = 0 ; j < scoreboard . length ; j ++ ) {
319- var found = false ;
320- var teamname = getTeamname ( scoreboard [ j ] ) ;
321- if ( teamname === null ) {
322- continue ;
323- }
324- var firstCol = getRank ( scoreboard [ j ] ) ;
325- var heartCol = getHeartCol ( scoreboard [ j ] ) ;
326- var rank = firstCol . innerHTML ;
327- for ( var i = 0 ; i < favTeams . length ; i ++ ) {
328- if ( teamname === favTeams [ i ] ) {
329- found = true ;
330- heartCol . innerHTML = addHeart ( rank , scoreboard [ j ] , j , found ) ;
331- toAdd [ cntFound ] = scoreboard [ j ] . cloneNode ( true ) ;
332- if ( rank . trim ( ) . length === 0 ) {
333- // make rank explicit in case of tie
334- getRank ( toAdd [ cntFound ] ) . innerHTML += lastRank ;
343+ Object . keys ( scoreboards ) . forEach ( function ( key ) {
344+ var toAdd = new Array ( ) ;
345+ var toAddMobile = new Array ( ) ;
346+ var cntFound = 0 ;
347+ var lastRank = 0 ;
348+ const scoreboard = scoreboards [ key ] ;
349+ const mobile = key === 'mobile' ;
350+ let teamIndex = 1 ;
351+ for ( var j = 0 ; j < scoreboard . length ; j ++ ) {
352+ var found = false ;
353+ var teamname = getTeamname ( scoreboard [ j ] ) ;
354+ if ( teamname === null ) {
355+ continue ;
356+ }
357+ var firstCol = getRank ( scoreboard [ j ] ) ;
358+ var heartCol = getHeartCol ( scoreboard [ j ] ) ;
359+ var rank = firstCol . innerHTML ;
360+ for ( var i = 0 ; i < favTeams . length ; i ++ ) {
361+ if ( teamname === favTeams [ i ] ) {
362+ found = true ;
363+ heartCol . innerHTML = addHeart ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
364+ toAdd [ cntFound ] = scoreboard [ j ] . cloneNode ( true ) ;
365+ if ( mobile ) {
366+ toAddMobile [ cntFound ] = scoreboard [ j + 1 ] . cloneNode ( true ) ;
367+ }
368+ if ( rank . trim ( ) . length === 0 ) {
369+ // make rank explicit in case of tie
370+ getRank ( toAdd [ cntFound ] ) . innerHTML += lastRank ;
371+ }
372+ scoreboard [ j ] . style . background = "lightyellow" ;
373+ const scoretn = scoreboard [ j ] . querySelector ( '.scoretn' ) ;
374+ if ( scoretn && scoretn . classList . contains ( 'cl_FFFFFF' ) ) {
375+ scoretn . classList . remove ( 'cl_FFFFFF' ) ;
376+ scoretn . classList . add ( 'cl_FFFFE0' ) ;
377+ }
378+ if ( mobile ) {
379+ scoreboard [ j + 1 ] . style . background = "lightyellow" ;
380+ }
381+ cntFound ++ ;
382+ break ;
335383 }
336- scoreboard [ j ] . style . background = "lightyellow" ;
337- cntFound ++ ;
338- break ;
339384 }
385+ if ( ! found ) {
386+ heartCol . innerHTML = addHeart ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
387+ }
388+ if ( rank !== "" ) {
389+ lastRank = rank ;
390+ }
391+
392+ teamIndex ++ ;
340393 }
341- if ( ! found ) {
342- heartCol . innerHTML = addHeart ( rank , scoreboard [ j ] , j , found ) ;
343- }
344- if ( rank !== "" ) {
345- lastRank = rank ;
346- }
347- }
348394
349- // copy favourite teams to the top of the scoreboard
350- for ( var i = 0 ; i < cntFound ; i ++ ) {
351- var copy = toAdd [ i ] ;
352- var style = "" ;
353- if ( i === 0 ) {
354- style += "border-top: 2px solid black;" ;
395+ let addCounter = 1 ;
396+ const copyRow = function ( i , copy , addTopBorder , addBottomBorder , noMiddleBorder ) {
397+ let style = "" ;
398+ if ( noMiddleBorder ) {
399+ style += "border-bottom-width: 0;" ;
400+ }
401+ if ( addTopBorder && i === 0 ) {
402+ style += "border-top: 2px solid black;" ;
403+ }
404+ if ( addBottomBorder && i === cntFound - 1 ) {
405+ style += "border-bottom: thick solid black;" ;
406+ }
407+ copy . setAttribute ( "style" , style ) ;
408+ const tbody = scoreboard [ 1 ] . parentNode ;
409+ tbody . insertBefore ( copy , scoreboard [ addCounter ] ) ;
410+ addCounter ++ ;
355411 }
356- if ( i === cntFound - 1 ) {
357- style += "border-bottom: thick solid black;" ;
412+
413+ // copy favourite teams to the top of the scoreboard
414+ for ( let i = 0 ; i < cntFound ; i ++ ) {
415+ copyRow ( i , toAdd [ i ] , true , ! mobile , mobile ) ;
416+ if ( mobile ) {
417+ copyRow ( i , toAddMobile [ i ] , false , true , false ) ;
418+ }
358419 }
359- copy . setAttribute ( "style" , style ) ;
360- var tbody = scoreboard [ 1 ] . parentNode ;
361- tbody . insertBefore ( copy , scoreboard [ i + 1 ] ) ;
362- }
420+ } ) ;
363421}
364422
365423// This function is a specific addition for using DOMjudge within a
0 commit comments