-
Notifications
You must be signed in to change notification settings - Fork 0
Add episode summary display and update service worker cache version #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,16 +225,26 @@ async function getSeinfeldShowId() { | |
| return cachedShowId; | ||
| } | ||
|
|
||
| async function getEpisodeImage(season, episodeNumber) { | ||
| function stripHtml(html) { | ||
| if (!html) return ""; | ||
| const tmp = document.createElement("div"); | ||
| tmp.innerHTML = html; | ||
| return (tmp.textContent || tmp.innerText || "").trim(); | ||
| } | ||
|
|
||
| async function getEpisodeDetails(season, episodeNumber) { | ||
| const showId = await getSeinfeldShowId(); | ||
| const res = await fetch(TVMAZE_EPISODE_BY_NUMBER(showId, season, episodeNumber)); | ||
|
|
||
| if (!res.ok) throw new Error("Failed to fetch episode data."); | ||
|
|
||
| const data = await res.json(); | ||
| return data?.image?.original || data?.image?.medium || null; | ||
| return { | ||
| imageUrl: data?.image?.original || data?.image?.medium || null, | ||
| summary: stripHtml(data?.summary) || "No summary available." | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| function showImage(url) { | ||
| episodeImage.classList.remove("loaded"); | ||
| episodeImage.src = ""; | ||
|
|
@@ -261,6 +271,7 @@ async function renderSample() { | |
| seasonEl.textContent = season; | ||
| episodeEl.textContent = episodeNumber; | ||
| titleEl.textContent = title; | ||
| summaryEl.textContent = "Loading summary..."; | ||
| netflixLink.href = NETFLIX_SEINFELD_URL; | ||
|
|
||
| result.classList.remove("hidden"); | ||
|
|
@@ -273,11 +284,12 @@ async function renderSample() { | |
| episodeImage.classList.add("hidden"); | ||
|
|
||
| try { | ||
| const imageUrl = await getEpisodeImage(season, episodeNumber); | ||
| imageFallback.textContent = "No episode image found"; | ||
| const { imageUrl, summary } = await getEpisodeDetails(season, episodeNumber); | ||
| summaryEl.textContent = summary; | ||
| showImage(imageUrl); | ||
| } catch { | ||
| imageFallback.textContent = "Could not load episode image"; | ||
| summaryEl.textContent = "Could not load episode summary."; | ||
| episodeImage.classList.add("hidden"); | ||
| imageFallback.classList.remove("hidden"); | ||
| } | ||
|
|
@@ -352,4 +364,6 @@ if ("serviceWorker" in navigator) { | |
| }); | ||
| } | ||
|
|
||
| const summaryEl = document.getElementById("summary"); | ||
|
|
||
|
Comment on lines
+367
to
+368
|
||
| initTheme(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const CACHE_NAME = "seinfeld-randomizer-v1"; | ||
| const CACHE_NAME = "seinfeld-randomizer-v2"; | ||
| const URLS_TO_CACHE = [ | ||
| "./", | ||
| "./index.html", | ||
|
Comment on lines
+1
to
4
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.