From fd96902e77e72692e1dc0cf141a27c1ee4338298 Mon Sep 17 00:00:00 2001 From: CatAClock <CatAClock@proton.me> Date: Sun, 11 May 2025 22:15:14 -0700 Subject: [PATCH] Fixed image bugs, Mastodon video --- JS/expanded.js | 21 +++++++++++++++++++-- JS/index.js | 12 ++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/JS/expanded.js b/JS/expanded.js index 3aa028e..8f7b69c 100644 --- a/JS/expanded.js +++ b/JS/expanded.js @@ -50,7 +50,7 @@ async function GetPost() { document.getElementsByClassName("Handle")[0].innerHTML = post.reblog.account.username + " ( R: " + post.account.username + " )"; if (post.reblog.media_attachments.length != 0) { for (let i of post.reblog.media_attachments) { - document.getElementsByClassName("Images")[0].innerHTML += "<img src=" + i.remote_url + " alt='" + i.description + "'/>"; + CreateMedia(i); } } } else { @@ -59,7 +59,7 @@ async function GetPost() { // Show the image if it exists. if (post.media_attachments.length != 0) { for (let i of post.media_attachments) { - document.getElementsByClassName("Images")[0].innerHTML += "<img src=" + i.remote_url + " alt='" + i.description + "'/>"; + CreateMedia(i); } } } @@ -102,6 +102,23 @@ async function GetPost() { } } +function CreateMedia(Media) { + // Check to see if the image is on the same server. + if (Media.type == "image") { + if (Media.remote_url == null) { + document.getElementsByClassName("Images")[0].innerHTML += "<img src=" + Media.url + " alt='" + Media.description + "'/>"; + } else { + document.getElementsByClassName("Images")[0].innerHTML += "<img src=" + Media.remote_url + " alt='" + Media.description + "'/>"; + } + } else if (Media.type == "video") { + if (Media.remote_url == null) { + document.getElementsByClassName("Images")[0].innerHTML += "<video controls src=" + Media.url + " alt='" + Media.description + "'></video>"; + } else { + document.getElementsByClassName("Images")[0].innerHTML += "<video controls src=" + Media.remote_url + " alt='" + Media.description + "'></video>"; + } + } +} + function SetFavorite() { FavoriteFlipper = !(FavoriteFlipper); if (FavoriteFlipper == false) { diff --git a/JS/index.js b/JS/index.js index a317e0a..e8e962d 100644 --- a/JS/index.js +++ b/JS/index.js @@ -198,11 +198,19 @@ async function PosterContainerUpdate(Direction) { // Check for images. Reblog roundabout fix included. if (MastodonLoadedFeed[CurrentThing + counter].reblog != null) { if (MastodonLoadedFeed[CurrentThing + counter].reblog.media_attachments.length != 0) { - i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!<br/>"; + if (MastodonLoadedFeed[CurrentThing + counter].reblog.media_attachments[0].type == "image") { + i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!<br/>"; + } else if (MastodonLoadedFeed[CurrentThing + counter].reblog.media_attachments[0].type == "video") { + i.getElementsByClassName("PostContent")[0].innerHTML += "This post has a video!<br/>"; + } } } else { if (MastodonLoadedFeed[CurrentThing + counter].media_attachments.length != 0) { - i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!<br/>"; + if (MastodonLoadedFeed[CurrentThing + counter].media_attachments[0].type == "image") { + i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!<br/>"; + } else if (MastodonLoadedFeed[CurrentThing + counter].media_attachments[0].type == "video") { + i.getElementsByClassName("PostContent")[0].innerHTML += "This post has a video!<br/>"; + } } } // Content warning. Don't show the content unless clicked!!!