From bbbf1d1967dc9eaaf06d6a9ef411ebf5a94b7adf Mon Sep 17 00:00:00 2001 From: daudix Date: Sun, 21 Jul 2024 22:46:11 +0300 Subject: [PATCH] Support more media attachment types in comments Types taken from https://github.com/dpecos/mastodon-comments/blob/master/mastodon-comments.js --- templates/partials/comments.html | 28 +++++++++++++++++++++++++++- templates/shortcodes/video.html | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/templates/partials/comments.html b/templates/partials/comments.html index bddab23..757fbef 100644 --- a/templates/partials/comments.html +++ b/templates/partials/comments.html @@ -196,7 +196,7 @@ main.innerHTML = status.content; let attachments = status.media_attachments; - let SUPPORTED_MEDIA = ["image", "gifv"]; + let SUPPORTED_MEDIA = ["image", "video", "gifv", "audio"]; let media = document.createElement("div"); media.className = "attachments"; if ( @@ -221,6 +221,19 @@ media.appendChild(mediaElement); break; + case "video": + mediaElement = document.createElement("video"); + mediaElement.setAttribute("src", attachment.url); + mediaElement.setAttribute("controls", ""); + + if (attachment.description != null) { + mediaElement.setAttribute("aria-title", attachment.description); + mediaElement.setAttribute("title", attachment.description); + } + + media.appendChild(mediaElement); + break; + case "gifv": mediaElement = document.createElement("video"); mediaElement.setAttribute("src", attachment.url); @@ -233,6 +246,19 @@ mediaElement.setAttribute("title", attachment.description); } + media.appendChild(mediaElement); + break; + + case "audio": + mediaElement = document.createElement("audio"); + mediaElement.setAttribute("src", attachment.url); + mediaElement.setAttribute("controls", ""); + + if (attachment.description != null) { + mediaElement.setAttribute("aria-title", attachment.description); + mediaElement.setAttribute("title", attachment.description); + } + media.appendChild(mediaElement); break; } diff --git a/templates/shortcodes/video.html b/templates/shortcodes/video.html index 5d18f42..be11aa2 100644 --- a/templates/shortcodes/video.html +++ b/templates/shortcodes/video.html @@ -6,5 +6,5 @@ {% if pixels %}pixels{% endif %} {% if transparent %}transparent{% endif %} " - {%- if alt -%}alt="{{ alt }}"{%- endif -%} + {%- if alt -%}aria-title="{{ alt }}"{%- endif -%} controls src="{{ url }}">