Skip to content

Commit

Permalink
Fix bug caused by using dom/selector in inline scripts, which breaks …
Browse files Browse the repository at this point in the history
…TwitchLiveBox component
  • Loading branch information
pjmartorell committed May 6, 2024
1 parent 62d7d71 commit 6ab1d29
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/components/TwitchLiveBox.astro
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,20 @@ const { streamer = "ibai" } = Astro.props
</div>

<script is:inline>
import { $ } from "@/lib/dom-selector"

const CONFIG = {
MIDU_API_UPTIME_WORKER: "https://midudev-apis.midudev.workers.dev/uptime",
VELADA_DATE: "2024-07-13 19:00:00 GMT+0100",
TWITCH_PLAYER_URL: "https://player.twitch.tv",
}
const streamer = $("#streamer").value
const streamer = document.querySelector("#streamer").value
const isVeladaTime = new Date().getTime() >= new Date(CONFIG.VELADA_DATE).getTime()
if (isVeladaTime) {
fetch(`${CONFIG.MIDU_API_UPTIME_WORKER}/${streamer}`)
.then((res) => res.json())
.then(({ online }) => {
if (online) {
$("#live").style.display = "block"
$("#live-frame").innerHTML =
document.querySelector("#live").style.display = "block"
document.querySelector("#live-frame").innerHTML =
`<iframe src="${CONFIG.TWITCH_PLAYER_URL}/?channel=${streamer}&parent=${document.location.hostname}" frameborder="0" width="380" height="200" allowfullscreen="true" scrolling="no"></iframe>`
}
})
Expand All @@ -64,9 +62,9 @@ const { streamer = "ibai" } = Astro.props
})
}

const closeButton = $("#live-close")
const closeButton = document.querySelector("#live-close")
closeButton?.addEventListener("click", () => {
$("#live").style.display = "none"
$("#live").innerHTML = ""
document.querySelector("#live").style.display = "none"
document.querySelector("#live").innerHTML = ""
})
</script>

0 comments on commit 6ab1d29

Please sign in to comment.