Skip to content

Commit

Permalink
If dark mode, use dark mode logos for background (#117)
Browse files Browse the repository at this point in the history
- Use dark mode background logos when dark mode theme is active
  • Loading branch information
vasqued2 authored Sep 9, 2024
1 parent e6fbe9d commit 4bc76f6
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 19 deletions.
33 changes: 24 additions & 9 deletions dist/ha-teamtracker-card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ha-teamtracker-card.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/const.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export let VERSION = "v0.14.8";
export let VERSION = "v0.14.9";

export let GOLF_HEADSHOT_URL = "https://a.espncdn.com/i/headshots/golf/players/full/";
export let MMA_HEADSHOT_URL = "https://a.espncdn.com/i/headshots/mma/players/full/";
Expand Down
6 changes: 4 additions & 2 deletions src/render_bye.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ export function renderBye(c) {
const htmlTemplate = html`
<ha-card>
<div class="card">
<img class="team-bg" src="${c.logoBG[team]}" />
<img class="team-bg" src="${c.logoBG[team]}"
onerror="this.onerror=null; this.src='${c.logoBGAlternate[team]}';" />
<div class="card-content">
<div class="team">
<img src="${c.logo[team]}" />
<img class="logo" src="${c.logo[team]}"
onerror="this.onerror=null; this.src='${c.logoAlternate[team]}'; this.onerror=function() { this.src='${c.logoError[team]}'; };" />
<div class="name">${c.name[team]}</div>
</div>
<div class="bye">${c.byeTerm}</div>
Expand Down
6 changes: 4 additions & 2 deletions src/render_in.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export function renderIn(c) {
<ha-card>
<div class="card">
<div class="title">${c.title}</div>
<img class="team-bg" src="${c.logoBG[1]}" />
<img class="opponent-bg" src="${c.logoBG[2]}" />
<img class="team-bg" src="${c.logoBG[1]}"
onerror="this.onerror=null; this.src='${c.logoBGAlternate[1]}';" />
<img class="opponent-bg" src="${c.logoBG[2]}"
onerror="this.onerror=null; this.src='${c.logoBGAlternate[2]}';" />
<div class="card-content">
<div class="team">
<a class="left-clickable ${!c.url[1] ? 'disabled' : ''}" href="${c.url[1] ? c.url[1] : '#'}" target="_blank">
Expand Down
6 changes: 4 additions & 2 deletions src/render_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export function renderPost(c) {
<ha-card>
<div class="card">
<div class="title">${c.title}</div>
<img class="team-bg" src="${c.logoBG[1]}" />
<img class="opponent-bg" src="${c.logoBG[2]}" />
<img class="team-bg" src="${c.logoBG[1]}"
onerror="this.onerror=null; this.src='${c.logoBGAlternate[1]}';" />
<img class="opponent-bg" src="${c.logoBG[2]}"
onerror="this.onerror=null; this.src='${c.logoBGAlternate[2]}';" />
<div class="card-content">
<div class="team">
<a class="left-clickable ${!c.url[1] ? 'disabled' : ''}" href="${c.url[1] ? c.url[1] : '#'}" target="_blank">
Expand Down
6 changes: 4 additions & 2 deletions src/render_pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export function renderPre(c) {
<ha-card>
<div class="card">
<div class="title">${c.title}</div>
<img class="team-bg" src="${c.logoBG[1]}" />
<img class="opponent-bg" src="${c.logoBG[2]}" />
<img class="team-bg" src="${c.logoBG[1]}"
onerror="this.onerror=null; this.src='${c.logoBGAlternate[1]}';" />
<img class="opponent-bg" src="${c.logoBG[2]}"
onerror="this.onerror=null; this.src='${c.logoBGAlternate[2]}';" />
<div class="card-content">
<div class="team">
<a class="left-clickable ${!c.url[1] ? 'disabled' : ''}" href="${c.url[1] ? c.url[1] : '#'}" target="_blank">
Expand Down
12 changes: 12 additions & 0 deletions src/set_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ERROR_HEADSHOT_URL } from "./const.js";
//
export function initCardData(c) {
c.logoBG = [];
c.logoBGAlternate = [];
c.logo = [];
c.logoAlternate = [];
c.logoError = [];
Expand Down Expand Up @@ -81,6 +82,7 @@ export function setDefaults(t, lang, stateObj, c, o, sport, team, oppo) {
}
c.logoError[team] = ERROR_HEADSHOT_URL;
c.logoBG[team] = stateObj.attributes.team_logo;
c.logoBGAlternate[team] = stateObj.attributes.team_logo;
c.name[team] = stateObj.attributes.team_name;
if (o.teamURL == 'more-info') {
c.url[team] = null;
Expand All @@ -98,6 +100,7 @@ export function setDefaults(t, lang, stateObj, c, o, sport, team, oppo) {
}
c.logoError[oppo] = ERROR_HEADSHOT_URL;
c.logoBG[oppo] = stateObj.attributes.opponent_logo;
c.logoBGAlternate[oppo] = stateObj.attributes.opponent_logo;
c.name[oppo] = stateObj.attributes.opponent_name;
if (o.opponentURL == 'more-info') {
c.url[oppo] = null;
Expand All @@ -111,7 +114,16 @@ export function setDefaults(t, lang, stateObj, c, o, sport, team, oppo) {
c.playClock = stateObj.attributes.clock;
if (o.showLeague) {
c.logoBG[team] = stateObj.attributes.league_logo
c.logoBGAlternate[team] = stateObj.attributes.league_logo
c.logoBG[oppo] = stateObj.attributes.league_logo
c.logoBGAlternate[oppo] = stateObj.attributes.league_logo
}
if (c.logoBG[team] && o.darkMode) {
c.logoBG[team] = c.logoBG[team].replace('/500/', '/500-dark/')
}

if (c.logoBG[oppo] && o.darkMode) {
c.logoBG[oppo] = c.logoBG[oppo].replace('/500/', '/500-dark/')
}

c.score[team] = stateObj.attributes.team_score;
Expand Down

0 comments on commit 4bc76f6

Please sign in to comment.