@@ -301,27 +301,20 @@ function getScoreboards(mobile)
301301
302302function getRank ( row )
303303{
304- return row . getElementsByTagName ( "td" ) [ 0 ] ;
304+ return row . querySelector ( '.rank' ) ;
305305}
306306
307307function 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 ] ;
314314 break ;
315315 }
316316 }
317- if ( td === null ) {
318- td = tds [ 1 ] ;
319- }
320- if ( td !== null ) {
321- return td ;
322- }
323-
324- return null ;
317+ return td ;
325318}
326319
327320function getTeamname ( row )
@@ -394,10 +387,10 @@ function toggle(id, show, mobile)
394387 } ) ;
395388}
396389
397- function getHeartTd ( rank , row , id , isFav , mobile )
390+ function getHeart ( rank , row , id , isFav , mobile )
398391{
399392 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>" ;
401394}
402395
403396function initFavouriteTeams ( )
@@ -422,22 +415,32 @@ function initFavouriteTeams()
422415 if ( teamname === null ) {
423416 continue ;
424417 }
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+ }
426424 var heartCol = getHeartCol ( scoreboard [ j ] ) ;
427- var rank = firstCol . innerHTML ;
425+ if ( ! heartCol ) {
426+ continue ;
427+ }
428+ var rank = rankElement . innerHTML . trim ( ) ;
428429 for ( var i = 0 ; i < favTeams . length ; i ++ ) {
429430 if ( teamname === favTeams [ i ] ) {
430431 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 ) ;
434433 toAdd [ cntFound ] = scoreboard [ j ] . cloneNode ( true ) ;
435434 if ( mobile ) {
436435 toAddMobile [ cntFound ] = scoreboard [ j + 1 ] . cloneNode ( true ) ;
437436 }
438- if ( rank . trim ( ) . length === 0 ) {
437+ if ( rank . length === 0 ) {
439438 // 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+ }
441444 }
442445 scoreboard [ j ] . style . background = "lightyellow" ;
443446 const scoretn = scoreboard [ j ] . querySelector ( '.scoretn' ) ;
@@ -453,8 +456,7 @@ function initFavouriteTeams()
453456 }
454457 }
455458 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 ) ;
458460 }
459461 if ( rank !== "" ) {
460462 lastRank = rank ;
0 commit comments