This commit is contained in:
+17
-2
@@ -133,12 +133,27 @@ function renderResults(results) {
|
||||
}
|
||||
for (const item of results) {
|
||||
const node = cardTemplate.content.firstElementChild.cloneNode(true);
|
||||
const image = node.querySelector("img");
|
||||
const previewVideo = node.querySelector(".preview-hover");
|
||||
node.href = item.link;
|
||||
node.querySelector("img").src = item.thumbnailUrl || "https://placehold.co/1280x720/0a0a0a/ffffff?text=No+Preview";
|
||||
node.querySelector("img").alt = item.title;
|
||||
image.src = item.thumbnailUrl || "https://placehold.co/1280x720/0a0a0a/ffffff?text=Preview";
|
||||
image.alt = item.title;
|
||||
node.querySelector("h3").textContent = item.title;
|
||||
node.querySelector("p").textContent = item.reason;
|
||||
node.querySelector(".source-badge").textContent = item.source;
|
||||
if (item.previewVideoUrl) {
|
||||
previewVideo.src = item.previewVideoUrl;
|
||||
previewVideo.poster = item.thumbnailUrl || "";
|
||||
node.addEventListener("mouseenter", () => {
|
||||
previewVideo.classList.remove("hidden");
|
||||
previewVideo.play().catch(() => {});
|
||||
});
|
||||
node.addEventListener("mouseleave", () => {
|
||||
previewVideo.pause();
|
||||
previewVideo.currentTime = 0;
|
||||
previewVideo.classList.add("hidden");
|
||||
});
|
||||
}
|
||||
searchResults.appendChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user