Add video preview to clean-up dialog

b357e5d25e54bc9985d55d0cbe4d889365a6f42b

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +16 -9Showing whitespace changes
public/scripts/data-maid.js+16 -9
@@ -217,8 +217,9 @@ class DataMaidDialog {
217217 button.addEventListener('click', async () => {
218218 const item = button.closest('.dataMaidItem');
219219 const hash = item?.getAttribute('data-hash');
220+ const itemName = items.find(i => i.hash === hash)?.name;
220221 if (hash) {
221222 await this.view(prop, hash, itemName);
222223 }
223224 });
224225 });
@@ -304,13 +305,14 @@ class DataMaidDialog {
304305 * Opens the item view for a specific hash.
305306 * @param {string} prop Property name for the category
306307 * @param {string} hash Item hash to view
308+ * @param {string} name Name of the item to view
307309 * @private
308310 */
309311 async view(prop, hash, name) {
310312 const url = this.getViewUrl(hash);
311313 const isImage = ['images', 'avatarThumbnails', 'backgroundThumbnails'].includes(prop);
312314 const element = isImage
313315 ? await this.getViewElement(url, name)
314316 : await this.getTextViewElement(url);
315317 await callGenericPopup(element, POPUP_TYPE.DISPLAY, '', { large: true, wide: true });
316318 }
@@ -341,16 +343,21 @@ class DataMaidDialog {
341343 }
342344
343345 /**
344346 * Gets ana imagemedia element for viewing images or videos.
345347 * @param {string} url View URL
348+ * @param {string} name Name of the file
346349 * @returns {Promise<HTMLElement>} Image element
347350 * @private
348351 */
349352 async getViewElement(url, name) {
350- const img = document.createElement('img');
353+ const isVideo = /\.(mp4|webm|ogg|avi|mov|3gp|flv|mkv|wmv)$/i.test(name);
351- img.src = url;
354+ const mediaElement = document.createElement(isVideo ? 'video' : 'img');
352- img.classList.add('dataMaidImageView');
355+ if (mediaElement instanceof HTMLVideoElement) {
353- return img;
356+ mediaElement.controls = true;
357+ }
358+ mediaElement.src = url;
359+ mediaElement.classList.add('dataMaidImageView');
360+ return mediaElement;
354361 }
355362
356363 /**