MCPcopy Create free account
hub / github.com/Alphanimble/htmlstream / fixBrokenImages

Function fixBrokenImages

demo/chat/stream-actions.ts:37–56  ·  view source on GitHub ↗
(root: HTMLElement)

Source from the content-addressed store, hash-verified

35}
36
37function fixBrokenImages(root: HTMLElement): void {
38 root.querySelectorAll<HTMLImageElement>("img").forEach((img) => {
39 const src = img.getAttribute("src") ?? "";
40 if (BROKEN_IMAGE_HOSTS.some((host) => src.includes(host))) {
41 img.src = picsumFallback(img.alt || src);
42 }
43
44 if (img.dataset.streamFallbackBound) {
45 return;
46 }
47 img.dataset.streamFallbackBound = "1";
48 img.addEventListener("error", () => {
49 if (img.dataset.streamFallbackApplied) {
50 return;
51 }
52 img.dataset.streamFallbackApplied = "1";
53 img.src = picsumFallback(img.alt || "cat");
54 });
55 });
56}
57
58function tagMeowButtons(root: HTMLElement): void {
59 root.querySelectorAll<HTMLButtonElement>("button").forEach((btn) => {

Callers 1

enhanceStreamedContentFunction · 0.85

Calls 1

picsumFallbackFunction · 0.85

Tested by

no test coverage detected