Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ <h1 class="title">Seinfeld Random Episode</h1>
</div>

<h2 id="title" class="episode-title"></h2>
<p id="summary" class="episode-summary">Loading summary...</p>

<p class="swipe-hint">Swipe left or right on the image to get the next episode</p>

Expand Down
24 changes: 19 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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");
Expand All @@ -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);
Comment thread
OrF8 marked this conversation as resolved.
} catch {
imageFallback.textContent = "Could not load episode image";
summaryEl.textContent = "Could not load episode summary.";
episodeImage.classList.add("hidden");
imageFallback.classList.remove("hidden");
}
Expand Down Expand Up @@ -352,4 +364,6 @@ if ("serviceWorker" in navigator) {
});
}

const summaryEl = document.getElementById("summary");

Comment on lines +367 to +368

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

summaryEl is initialized at the bottom of the file, separated from the other DOM element lookups at the top. For readability and to avoid future ordering issues, consider moving this getElementById alongside the other const ...El = document.getElementById(...) declarations near the start.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

initTheme();
2 changes: 1 addition & 1 deletion service-worker.js
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

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caches.match(event.request) searches across all caches, so bumping CACHE_NAME alone may not guarantee clients get updated assets (an older cache can still satisfy the request). Add an activate handler to delete old cache names and/or change the fetch handler to match within CACHE_NAME specifically (e.g., caches.open(CACHE_NAME).then(cache => cache.match(req))).

Copilot uses AI. Check for mistakes.
Expand Down
7 changes: 7 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,11 @@ body.light-mode .badge {
width: 40px;
height: 40px;
}
}

.episode-summary {
color: var(--muted);
font-size: 0.98rem;
line-height: 1.5;
margin-bottom: 16px;
}
Loading