@@ -301,27 +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
- return td ;
322
- }
323
-
324
- return null ;
317
+ return td ;
325
318
}
326
319
327
320
function getTeamname ( row )
@@ -394,10 +387,10 @@ function toggle(id, show, mobile)
394
387
} ) ;
395
388
}
396
389
397
- function getHeartTd ( rank , row , id , isFav , mobile )
390
+ function getHeart ( rank , row , id , isFav , mobile )
398
391
{
399
392
var iconClass = isFav ? "fas fa-heart" : "far fa-heart" ;
400
- return "<td class=\"scoreaf heart\">< span class=\"heart " + iconClass + "\" onclick=\"toggle(" + id + "," + ( isFav ? "false" : "true" ) + "," + mobile + ")\"></span></td >" ;
393
+ return "<span class=\"heart " + iconClass + "\" onclick=\"toggle(" + id + "," + ( isFav ? "false" : "true" ) + "," + mobile + ")\"></span>" ;
401
394
}
402
395
403
396
function initFavouriteTeams ( )
@@ -422,22 +415,32 @@ function initFavouriteTeams()
422
415
if ( teamname === null ) {
423
416
continue ;
424
417
}
425
- 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
+ }
426
424
var heartCol = getHeartCol ( scoreboard [ j ] ) ;
427
- var rank = firstCol . innerHTML ;
425
+ if ( ! heartCol ) {
426
+ continue ;
427
+ }
428
+ var rank = rankElement . innerHTML . trim ( ) ;
428
429
for ( var i = 0 ; i < favTeams . length ; i ++ ) {
429
430
if ( teamname === favTeams [ i ] ) {
430
431
found = true ;
431
- let heartTd = getHeartTd ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
432
- // Insert td after heartCol
433
- heartCol . insertAdjacentHTML ( 'afterend' , heartTd ) ;
432
+ heartCol . innerHTML = getHeart ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
434
433
toAdd [ cntFound ] = scoreboard [ j ] . cloneNode ( true ) ;
435
434
if ( mobile ) {
436
435
toAddMobile [ cntFound ] = scoreboard [ j + 1 ] . cloneNode ( true ) ;
437
436
}
438
- if ( rank . trim ( ) . length === 0 ) {
437
+ if ( rank . length === 0 ) {
439
438
// make rank explicit in case of tie
440
- getRank ( toAdd [ cntFound ] ) . innerHTML += lastRank ;
439
+ if ( mobile ) {
440
+ getRank ( toAddMobile [ cntFound ] ) . innerHTML += lastRank ;
441
+ } else {
442
+ getRank ( toAdd [ cntFound ] ) . innerHTML += lastRank ;
443
+ }
441
444
}
442
445
scoreboard [ j ] . style . background = "lightyellow" ;
443
446
const scoretn = scoreboard [ j ] . querySelector ( '.scoretn' ) ;
@@ -453,8 +456,7 @@ function initFavouriteTeams()
453
456
}
454
457
}
455
458
if ( ! found ) {
456
- let heartTd = getHeartTd ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
457
- heartCol . insertAdjacentHTML ( 'afterend' , heartTd ) ;
459
+ heartCol . innerHTML = getHeart ( rank , scoreboard [ j ] , teamIndex , found , mobile ) ;
458
460
}
459
461
if ( rank !== "" ) {
460
462
lastRank = rank ;
0 commit comments