Skip to content

Commit

Permalink
Fix runaway style appending
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Meek authored May 17, 2019
1 parent 30cae35 commit 0d318d8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions upcoming-media-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class UpcomingMediaCard extends HTMLElement {
this.appendChild(card);
}
// The Great Wall of Config & Defaults™
const style = document.createElement('style');
let style = document.createElement('style');
style.setAttribute("id", "umc_style");
var service = this.config.service;
const entity = this.config.entity || `sensor.${service}_upcoming_media`;
if (!hass.states[entity]) {
Expand Down Expand Up @@ -57,7 +58,7 @@ class UpcomingMediaCard extends HTMLElement {
const max = Math.min(json.length - 1, this.config.max || 5);
window.cardSize = max;

if (view == 'poster') {
if (view == 'poster' && !this.querySelector('[id="umc_style"]')) {
style.textContent = `
.${service}_${view} {
width:100%;
Expand Down Expand Up @@ -146,7 +147,7 @@ class UpcomingMediaCard extends HTMLElement {
fill:${line4_color};
}
`;
} else {
} else if (!this.querySelector('[id="umc_style"]')) {
style.textContent = `
.${service}_${view} {
width:100%;
Expand Down Expand Up @@ -389,7 +390,7 @@ class UpcomingMediaCard extends HTMLElement {
</div>
`;
}
this.appendChild(style);
if (!this.querySelector('[id="umc_style"]')) this.appendChild(style);
}
}
setConfig(config) {
Expand Down

0 comments on commit 0d318d8

Please sign in to comment.