Update app.js

This commit is contained in:
2026-04-22 23:21:43 +02:00
parent 3762dd12db
commit 803f17fde4
+8 -8
View File
@@ -284,15 +284,15 @@ function ansiToHtml(text) {
}
out += s.slice(last);
if (spans > 0) out += '</span>'.repeat(spans);
// Linkify — detect images/video for inline preview toggle
return out.replace(/(https?:\/\/[^\s<>"&]+)/g, (url) => {
const clean = url.replace(/&amp;/g,'&');
const isImg = /\.(png|jpe?g|gif|webp|svg|bmp)(\?.*)?$/i.test(clean);
const isVid = /\.(mp4|webm|ogv|mov)(\?.*)?$/i.test(clean);
const preview = (isImg || isVid)
? `<button class="media-toggle" data-url="${url}" data-type="${isImg?'img':'vid'}" title="Show/hide media">▶</button>`
// Linkify URLs; match through &amp; so query strings aren't cut short
return out.replace(/https?:\/\/(?:[^\s<>"\']|&amp;)+/g, (url) => {
const href = url.replace(/&amp;/g, '&');
const isImg = /\.(png|jpe?g|gif|webp|svg|bmp)(\?.*)?$/i.test(href);
const isVid = /\.(mp4|webm|ogv|mov)(\?.*)?$/i.test(href);
const btn = (isImg || isVid)
? ` <button class="media-toggle" data-url="${href}" data-type="${isImg?'img':'vid'}" title="Show/hide">&#9654;</button>`
: '';
return `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>${preview}`;
return `<a href="${href}" target="_blank" rel="noopener noreferrer">${url}</a>${btn}`;
});
}