@@ -301,30 +301,20 @@ function getScoreboards(mobile)
301
301
302
302
function getRank ( row )
303
303
{
304
- return row . getElementsByTagName ( "td" ) [ 0 ] ;
304
+ return row . querySelector ( '.rank' ) ;
305
305
}
306
306
307
307
function getHeartCol ( row ) {
308
- var tds = row . getElementsByTagName ( "td" ) ;
309
- var td = null ;
310
- // search for td before the team name
311
- for ( var i = 1 ; i < 4 ; i ++ ) {
312
- if ( tds [ i ] . classList . contains ( "scoretn " ) ) {
313
- td = tds [ i - 1 ] ;
308
+ const tds = row . getElementsByTagName ( "td" ) ;
309
+ let td = null ;
310
+ // search for td to store the hearts
311
+ for ( let i = 1 ; i < 5 ; i ++ ) {
312
+ if ( tds [ i ] && tds [ i ] . classList . contains ( "heart " ) ) {
313
+ td = tds [ i ] ;
314
314
break ;
315
315
}
316
316
}
317
- if ( td === null ) {
318
- td = tds [ 1 ] ;
319
- }
320
- if ( td !== null ) {
321
- if ( td . children . length ) {
322
- return td . children [ 0 ] ;
323
- }
324
- return td ;
325
- }
326
-
327
- return null ;
317
+ return td ;
328
318
}
329
319
330
320
function getTeamname ( row )
@@ -397,11 +387,10 @@ function toggle(id, show, mobile)
397
387
} ) ;
398
388
}
399
389
400
- function addHeart ( rank , row , id , isFav , mobile )
390
+ function getHeart ( rank , row , id , isFav , mobile )
401
391
{
402
- var heartCol = getHeartCol ( row ) ;
403
392
var iconClass = isFav ? "fas fa-heart" : "far fa-heart" ;
404
- return heartCol . innerHTML + "<span class=\"heart " + iconClass + "\" onclick=\"toggle(" + id + "," + ( isFav ? "false" : "true" ) + "," + mobile + ")\"></span>" ;
393
+ return "<span class=\"heart " + iconClass + "\" onclick=\"toggle(" + id + "," + ( isFav ? "false" : "true" ) + "," + mobile + ")\"></span>" ;
405
394
}
406
395
407
396
function initFavouriteTeams ( )
@@ -426,20 +415,32 @@ function initFavouriteTeams()
426
415
if ( teamname === null ) {
427
416
continue ;
428
417
}
429
- var firstCol = getRank ( scoreboard [ j ] ) ;
418
+ let rankElement ;
419
+ if ( mobile ) {
420
+ rankElement = getRank ( scoreboard [ j + 1 ] ) ;
421
+ } else {
422
+ rankElement = getRank ( scoreboard [ j ] ) ;
423
+ }
430
424
var heartCol = getHeartCol ( scoreboard [ j ] ) ;
431
- var rank = firstCol . innerHTML ;
425
+ if ( ! heartCol ) {
426
+ continue ;
427
+ }
428
+ var rank = rankElement . innerHTML . trim ( ) ;
432
429
for ( var i = 0 ; i < favTeams . length ; i ++ ) {
433
430
if ( teamname === favTeams [ i ] ) {
434
431
found = true ;
435
- heartCol . innerHTML = addHeart ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
432
+ heartCol . innerHTML = getHeart ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
436
433
toAdd [ cntFound ] = scoreboard [ j ] . cloneNode ( true ) ;
437
434
if ( mobile ) {
438
435
toAddMobile [ cntFound ] = scoreboard [ j + 1 ] . cloneNode ( true ) ;
439
436
}
440
- if ( rank . trim ( ) . length === 0 ) {
437
+ if ( rank . length === 0 ) {
441
438
// make rank explicit in case of tie
442
- getRank ( toAdd [ cntFound ] ) . innerHTML += lastRank ;
439
+ if ( mobile ) {
440
+ getRank ( toAddMobile [ cntFound ] ) . innerHTML += lastRank ;
441
+ } else {
442
+ getRank ( toAdd [ cntFound ] ) . innerHTML += lastRank ;
443
+ }
443
444
}
444
445
scoreboard [ j ] . style . background = "lightyellow" ;
445
446
const scoretn = scoreboard [ j ] . querySelector ( '.scoretn' ) ;
@@ -455,7 +456,7 @@ function initFavouriteTeams()
455
456
}
456
457
}
457
458
if ( ! found ) {
458
- heartCol . innerHTML = addHeart ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
459
+ heartCol . innerHTML = getHeart ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
459
460
}
460
461
if ( rank !== "" ) {
461
462
lastRank = rank ;
0 commit comments