youtube: Request medium-quality preview images.

This commit is contained in:
Karl Stolley
2025-03-05 13:14:50 -06:00
committed by Tim Abbott
parent 0ce3bbd09d
commit 80dcd53b59
6 changed files with 37 additions and 12 deletions

View File

@@ -1,3 +1,5 @@
import assert from "minimalistic-assert";
import {$t} from "./i18n.ts";
import * as thumbnail from "./thumbnail.ts";
import {user_settings} from "./user_settings.ts";
@@ -52,6 +54,18 @@ export function postprocess_content(html: string): string {
elt.removeAttribute("target");
}
// Update older, smaller default.jpg YouTube preview images
// with higher-quality preview images (320px wide)
if (elt.parentElement?.classList.contains("youtube-video")) {
const img = elt.querySelector("img");
assert(img instanceof HTMLImageElement);
const img_src = img.src;
if (img_src.endsWith("/default.jpg")) {
const mq_src = img_src.replace(/\/default.jpg$/, "/mqdefault.jpg");
img.src = mq_src;
}
}
if (elt.parentElement?.classList.contains("message_inline_image")) {
// For inline images we want to handle the tooltips explicitly, and disable
// the browser's built in handling of the title attribute.