Support more media attachment types in comments

Types taken from
https://github.com/dpecos/mastodon-comments/blob/master/mastodon-comments.js
This commit is contained in:
daudix
2024-07-21 22:46:11 +03:00
parent 3625196398
commit bbbf1d1967
2 changed files with 28 additions and 2 deletions

View File

@ -196,7 +196,7 @@
main.innerHTML = status.content; main.innerHTML = status.content;
let attachments = status.media_attachments; let attachments = status.media_attachments;
let SUPPORTED_MEDIA = ["image", "gifv"]; let SUPPORTED_MEDIA = ["image", "video", "gifv", "audio"];
let media = document.createElement("div"); let media = document.createElement("div");
media.className = "attachments"; media.className = "attachments";
if ( if (
@ -221,6 +221,19 @@
media.appendChild(mediaElement); media.appendChild(mediaElement);
break; 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": case "gifv":
mediaElement = document.createElement("video"); mediaElement = document.createElement("video");
mediaElement.setAttribute("src", attachment.url); mediaElement.setAttribute("src", attachment.url);
@ -233,6 +246,19 @@
mediaElement.setAttribute("title", attachment.description); 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); media.appendChild(mediaElement);
break; break;
} }

View File

@ -6,5 +6,5 @@
{% if pixels %}pixels{% endif %} {% if pixels %}pixels{% endif %}
{% if transparent %}transparent{% endif %} {% if transparent %}transparent{% endif %}
" "
{%- if alt -%}alt="{{ alt }}"{%- endif -%} {%- if alt -%}aria-title="{{ alt }}"{%- endif -%}
controls src="{{ url }}"></video> controls src="{{ url }}"></video>