commit 9be8194dace1f8236713cf602afe91e290fd5f41
parent 4f27647c5bad5fadadd4cc2cdf019e6b06c9a461
Author: William Casarin <jb55@jb55.com>
Date: Fri, 4 Nov 2022 13:25:59 -0700
web: inline video support
Diffstat:
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/webv2/damus.js b/webv2/damus.js
@@ -950,17 +950,28 @@ function render_action_bar(ev) {
`
}
-const IMG_REGEX = /(png|jpeg)$/i
+const IMG_REGEX = /(png|jpeg|jpg|gif|webp)$/i
function is_img_url(path) {
return IMG_REGEX.test(path)
}
+const VID_REGEX = /(webm|mp4)$/i
+function is_video_url(path) {
+ return VID_REGEX.test(path)
+}
+
const URL_REGEX = /(https?:\/\/[^\s\):]+)/g;
function linkify(text) {
return text.replace(URL_REGEX, function(url) {
const parsed = new URL(url)
if (is_img_url(parsed.pathname))
- return `<img class="inline-img" src="${url}">`;
+ return `<img class="inline-img" src="${url}"/>`;
+ else if (is_video_url(parsed.pathname))
+ return `
+ <video controls class="inline-img" />
+ <source src="${url}">
+ </video>
+ `;
else
return `<a target="_blank" rel="noopener noreferrer" href="${url}">${url}</a>`;
})
diff --git a/webv2/index.html b/webv2/index.html
@@ -41,7 +41,7 @@
<script src="noble-secp256k1.js?v=1"></script>
<script src="bech32.js?v=1"></script>
<script src="nostr.js?v=6"></script>
- <script src="damus.js?v=45"></script>
+ <script src="damus.js?v=46"></script>
<script>
// I have to delay loading to wait for nos2x
const relay = setTimeout(damus_web_init, 100)