Add video poster frames and rework the media status row

This commit is contained in:
Fisto
2026-09-16 12:40:10 +02:00
parent f9b4041157
commit 043d1cd3c5
9 changed files with 124 additions and 12 deletions
+2 -1
View File
@@ -99,7 +99,8 @@
cursor: pointer;
}
.vk-media-media img {
.vk-media-media img,
.vk-media-media video {
width: 100%;
height: 100%;
object-fit: cover;
+18 -3
View File
@@ -194,8 +194,8 @@
function renderStatus() {
const stats = state.stats ?? { total: 0, downloaded: 0, cached: 0, notDownloaded: 0 };
setStatus(
`downloaded ${stats.downloaded}/${stats.total} (images/videos) | ` +
`cached ${stats.cached}/${stats.notDownloaded} (excludes downloaded) | ${state.items.length} loaded`
`(Images/Videos) | Downloaded ${stats.downloaded}/${stats.total} | ` +
`Cached ${stats.cached}/${stats.total} (excl Downl) | Loaded ${state.items.length}/${stats.total}`
);
}
@@ -403,12 +403,27 @@
const source = gridSource(item);
const visual = item.kind === "image" || item.kind === "gif" || item.kind === "video";
if (visual && /^(https?:|\/)/.test(source)) {
if (visual && /^(https?:|\/)/.test(source) && item.kind !== "video") {
const img = document.createElement("img");
img.loading = "lazy";
img.src = source;
img.alt = item.kind;
media.append(img);
} else if (item.kind === "video" && /^(https?:|\/)/.test(source)) {
// Discord has no server-side video thumbnails; the browser shows the first frame.
const video = document.createElement("video");
video.preload = "metadata";
video.muted = true;
video.playsInline = true;
video.src = source;
video.addEventListener(
"loadedmetadata",
() => {
if (video.duration) video.currentTime = Math.min(0.1, video.duration / 2);
},
{ once: true }
);
media.append(video);
} else {
media.append(el("span", "vk-media-card-kind", item.kind.toUpperCase()));
}