Skip to content

Commit e4e4a05

Browse files
authored
🔀 Merge pull request #7 from LoupesDEV/alert-autofix-10
Potential fix for code scanning alert no. 10: DOM text reinterpreted as HTML
2 parents c8e2797 + a6bee38 commit e4e4a05

1 file changed

Lines changed: 65 additions & 19 deletions

File tree

js/display.js

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ export function openDetails(item) {
8686
renderEpisodes(seasons[seasonKeys[0]], seasonKeys[0]);
8787

8888
seasonSelect.onchange = (e) => {
89-
renderEpisodes(seasons[e.target.value], e.target.value);
89+
const selectedKey = e.target && typeof e.target.value === 'string' ? e.target.value : null;
90+
const selectedSeason = selectedKey && Object.prototype.hasOwnProperty.call(seasons, selectedKey)
91+
? seasons[selectedKey]
92+
: null;
93+
if (selectedSeason) {
94+
renderEpisodes(selectedSeason, selectedKey);
95+
}
9096
};
9197
} else {
9298
const opt = document.createElement('option');
@@ -136,24 +142,64 @@ function renderEpisodes(episodes, seasonNum) {
136142
const fallbackThumb = `https://placehold.co/300x200/333/666?text=S${seasonNum}-EP${idx + 1}`;
137143
const thumbUrl = activeDetailItem ? activeDetailItem.banner : fallbackThumb;
138144

139-
row.innerHTML = `
140-
<div class="flex items-center gap-6 w-full md:w-auto">
141-
<span class="text-2xl font-black text-gray-600 group-hover:text-red-500 transition-colors w-8 text-center">${idx + 1}</span>
142-
<div class="relative w-40 h-24 flex-shrink-0 bg-gray-900 rounded-lg overflow-hidden shadow-lg">
143-
<img src="${thumbUrl}" onerror="this.src='${fallbackThumb}'" class="w-full h-full object-cover opacity-70 group-hover:opacity-100 transition-all duration-500 scale-100 group-hover:scale-110">
144-
<div class="absolute inset-0 flex items-center justify-center bg-black/20 group-hover:bg-black/40 transition-colors">
145-
<i class="fas fa-play text-white text-xl opacity-0 group-hover:opacity-100 transition-all"></i>
146-
</div>
147-
</div>
148-
</div>
149-
<div class="flex-1 w-full text-center md:text-left overflow-hidden">
150-
<div class="flex flex-col md:flex-row md:items-center justify-between gap-2 mb-2">
151-
<h4 class="font-bold text-white text-xl truncate group-hover:text-red-400 transition-colors">${ep.title}</h4>
152-
<span class="text-sm font-bold text-gray-400 bg-black/30 px-2 py-1 rounded-md">${ep.duration || '45m'}</span>
153-
</div>
154-
<p class="text-gray-400 text-sm leading-relaxed line-clamp-2">${ep.desc || "..."}</p>
155-
</div>
156-
`;
145+
// Left container: index + thumbnail
146+
const leftContainer = document.createElement('div');
147+
leftContainer.className = "flex items-center gap-6 w-full md:w-auto";
148+
149+
const indexSpan = document.createElement('span');
150+
indexSpan.className = "text-2xl font-black text-gray-600 group-hover:text-red-500 transition-colors w-8 text-center";
151+
indexSpan.textContent = String(idx + 1);
152+
leftContainer.appendChild(indexSpan);
153+
154+
const thumbContainer = document.createElement('div');
155+
thumbContainer.className = "relative w-40 h-24 flex-shrink-0 bg-gray-900 rounded-lg overflow-hidden shadow-lg";
156+
157+
const img = document.createElement('img');
158+
img.src = thumbUrl;
159+
img.className = "w-full h-full object-cover opacity-70 group-hover:opacity-100 transition-all duration-500 scale-100 group-hover:scale-110";
160+
img.onerror = function () {
161+
this.src = fallbackThumb;
162+
};
163+
thumbContainer.appendChild(img);
164+
165+
const overlay = document.createElement('div');
166+
overlay.className = "absolute inset-0 flex items-center justify-center bg-black/20 group-hover:bg-black/40 transition-colors";
167+
168+
const playIcon = document.createElement('i');
169+
playIcon.className = "fas fa-play text-white text-xl opacity-0 group-hover:opacity-100 transition-all";
170+
overlay.appendChild(playIcon);
171+
172+
thumbContainer.appendChild(overlay);
173+
leftContainer.appendChild(thumbContainer);
174+
175+
// Right container: title, duration, description
176+
const rightContainer = document.createElement('div');
177+
rightContainer.className = "flex-1 w-full text-center md:text-left overflow-hidden";
178+
179+
const titleRow = document.createElement('div');
180+
titleRow.className = "flex flex-col md:flex-row md:items-center justify-between gap-2 mb-2";
181+
182+
const titleEl = document.createElement('h4');
183+
titleEl.className = "font-bold text-white text-xl truncate group-hover:text-red-400 transition-colors";
184+
titleEl.textContent = ep.title;
185+
186+
const durationEl = document.createElement('span');
187+
durationEl.className = "text-sm font-bold text-gray-400 bg-black/30 px-2 py-1 rounded-md";
188+
durationEl.textContent = ep.duration || '45m';
189+
190+
titleRow.appendChild(titleEl);
191+
titleRow.appendChild(durationEl);
192+
193+
const descEl = document.createElement('p');
194+
descEl.className = "text-gray-400 text-sm leading-relaxed line-clamp-2";
195+
descEl.textContent = ep.desc || "...";
196+
197+
rightContainer.appendChild(titleRow);
198+
rightContainer.appendChild(descEl);
199+
200+
row.appendChild(leftContainer);
201+
row.appendChild(rightContainer);
202+
157203
row.onclick = (e) => {
158204
e.stopPropagation();
159205
playVideo(ep.video);

0 commit comments

Comments
 (0)