This commit is contained in:
+30
-4
@@ -270,6 +270,33 @@ function attachVideoSource(video, src) {
|
||||
logEvent("preview:attach:file", { src });
|
||||
}
|
||||
|
||||
function startHoverPreview(video, src) {
|
||||
if (!src) {
|
||||
return;
|
||||
}
|
||||
attachVideoSource(video, src);
|
||||
video.classList.remove("hidden");
|
||||
const attemptPlay = () => {
|
||||
video.play().catch((error) => {
|
||||
logEvent("preview:hover:play:error", { src, message: String(error) });
|
||||
});
|
||||
};
|
||||
if (video.readyState >= 2) {
|
||||
attemptPlay();
|
||||
return;
|
||||
}
|
||||
const onReady = () => {
|
||||
video.removeEventListener("loadeddata", onReady);
|
||||
video.removeEventListener("canplay", onReady);
|
||||
attemptPlay();
|
||||
};
|
||||
video.addEventListener("loadeddata", onReady, { once: true });
|
||||
video.addEventListener("canplay", onReady, { once: true });
|
||||
if (video.load) {
|
||||
video.load();
|
||||
}
|
||||
}
|
||||
|
||||
function detachVideoSource(video) {
|
||||
const existing = hlsInstances.get(video);
|
||||
if (existing) {
|
||||
@@ -299,21 +326,20 @@ function renderResults(results) {
|
||||
node.querySelector(".result-snippet").textContent = item.snippet || item.reason || item.source || "";
|
||||
node.querySelector(".result-reason").textContent = item.reason ? `AI note: ${item.reason}` : "";
|
||||
node.querySelector(".source-badge").textContent = item.source;
|
||||
previewVideo.poster = item.thumbnailUrl || "";
|
||||
if (item.previewVideoUrl) {
|
||||
attachVideoSource(previewVideo, item.previewVideoUrl);
|
||||
previewVideo.poster = item.thumbnailUrl || "";
|
||||
const mediaArea = node.querySelector(".relative");
|
||||
mediaArea.addEventListener("mouseenter", () => {
|
||||
logEvent("preview:hover:start", { title: item.title, source: item.source, previewVideoUrl: item.previewVideoUrl });
|
||||
overlays.forEach((overlay) => overlay.classList.add("hidden"));
|
||||
previewVideo.classList.remove("hidden");
|
||||
previewVideo.play().catch(() => {});
|
||||
startHoverPreview(previewVideo, item.previewVideoUrl);
|
||||
});
|
||||
mediaArea.addEventListener("mouseleave", () => {
|
||||
logEvent("preview:hover:end", { title: item.title, source: item.source });
|
||||
previewVideo.pause();
|
||||
previewVideo.currentTime = 0;
|
||||
previewVideo.classList.add("hidden");
|
||||
detachVideoSource(previewVideo);
|
||||
overlays.forEach((overlay) => overlay.classList.remove("hidden"));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user