From 5dbc2a2b44357af5dd68f2c965278a1ae6edd4c5 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Thu, 22 May 2025 15:52:19 -0700 Subject: [PATCH] Threads and a few bug fixes with links --- HTML/expanded.html | 8 ++++++++ JS/expanded.js | 38 ++++++++++++++++++++++++++++++-------- JS/index.js | 25 +++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/HTML/expanded.html b/HTML/expanded.html index 391a069..1c5dc91 100644 --- a/HTML/expanded.html +++ b/HTML/expanded.html @@ -13,10 +13,18 @@ +
+

+

+


+
+

+

+


diff --git a/JS/expanded.js b/JS/expanded.js index 910a430..ab48295 100644 --- a/JS/expanded.js +++ b/JS/expanded.js @@ -15,7 +15,7 @@ let BoostFlipper = false; let website = document.location.href.split("website=")[1]; let post = JSON.parse(localStorage.getItem("post")); -document.getElementsByClassName("Origin")[0].innerHTML = website; +document.getElementsByClassName("Origin Regular")[0].innerHTML = website; GetPost(); // Button stuff @@ -47,7 +47,7 @@ async function GetPost() { // Check for a reblog. if (post.reblog != null) { document.getElementsByClassName("PostText Regular")[0].innerHTML = post.reblog.content; - document.getElementsByClassName("Handle")[0].innerHTML = post.reblog.account.username + " ( R: " + post.account.username + " )"; + document.getElementsByClassName("Handle Regular")[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) { await CreateMedia(i, document.getElementsByClassName("Images Regular")[0]); @@ -55,7 +55,7 @@ async function GetPost() { } } else { document.getElementsByClassName("PostText Regular")[0].innerHTML = post.content; - document.getElementsByClassName("Handle")[0].innerHTML = post.account.username; + document.getElementsByClassName("Handle Regular")[0].innerHTML = post.account.username; // Show the image if it exists. if (post.media_attachments.length != 0) { for (let i of post.media_attachments) { @@ -71,6 +71,7 @@ async function GetPost() { // Now time to see if there are any parents if (post.in_reply_to_id != null) { var AnotherPost = await MastodonAPI.GetStatus(post.in_reply_to_id); + document.getElementsByClassName("Origin Parent")[0].innerHTML = website; if (AnotherPost.reblog != null) { document.getElementsByClassName("PostText Parent")[0].innerHTML = AnotherPost.reblog.content; if (AnotherPost.reblog.media_attachments.length != 0) { @@ -89,6 +90,7 @@ async function GetPost() { // Now time to see if there are any grandparents if (AnotherPost.in_reply_to_id != null) { var AnotherAnotherPost = await MastodonAPI.GetStatus(AnotherPost.in_reply_to_id); + document.getElementsByClassName("Origin GrandParent")[0].innerHTML = website; if (AnotherAnotherPost.reblog != null) { document.getElementsByClassName("PostText GrandParent")[0].innerHTML = AnotherAnotherPost.reblog.content; if (AnotherAnotherPost.reblog.media_attachments.length != 0) { @@ -109,12 +111,28 @@ async function GetPost() { } else if (website == "Bluesky") { // Check for a reblog. if (post.hasOwnProperty("reason") && post.reason.$type == "app.bsky.feed.defs#reasonRepost") { - document.getElementsByClassName("PostText Regular")[0].innerHTML = post.post.record.text; - document.getElementsByClassName("Handle")[0].innerHTML = post.post.author.handle + " ( R: " + post.reason.by.handle + " )"; + document.getElementsByClassName("Handle Regular")[0].innerHTML = post.post.author.handle + " ( R: " + post.reason.by.handle + " )"; } else { - document.getElementsByClassName("PostText Regular")[0].innerHTML = post.post.record.text; - document.getElementsByClassName("Handle")[0].innerHTML = post.post.author.handle; + document.getElementsByClassName("Handle Regular")[0].innerHTML = post.post.author.handle; } + // Text. This will be modified later. + var Text = post.post.record.text; + // Check for facets. Facets are things that change what the text does or looks like. + if (post.post.record.hasOwnProperty("facets")) { + for (let i of post.post.record.facets) { + if (i.features[0].$type == "app.bsky.richtext.facet#link") { + var EmojiRegex = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu; + var EmojiObjects = Text.match(EmojiRegex); + var SubtractNumber = 0; + if (EmojiObjects != null) { + SubtractNumber = EmojiObjects.length * 2; + } + Text = Text.substring(0, i.index.byteStart - SubtractNumber) + "" + Text.substring(i.index.byteStart - SubtractNumber, i.index.byteEnd - SubtractNumber) + "" + Text.substring(i.index.byteEnd - SubtractNumber, Text.length - 1); + } + } + } + // Place the text. + document.getElementsByClassName("PostText Regular")[0].innerHTML = Text; // Show the image if it exists. if (post.post.record.hasOwnProperty("embed")) { await CreateMedia(post.post.record, document.getElementsByClassName("Images Regular")[0], post.post.author.did); @@ -134,14 +152,18 @@ async function GetPost() { // Now time to see if there are any parents. if (post.hasOwnProperty("reply")) { var AnotherPost = await BlueskyAPI.GetRecord(post.reply.parent.uri.split("/")[2], post.reply.parent.uri.split("/")[3], post.reply.parent.uri.split("/")[4]); - console.log(AnotherPost); + document.getElementsByClassName("Origin Parent")[0].innerHTML = website; + document.getElementsByClassName("Handle Parent")[0].innerHTML = post.reply.parent.author.handle; document.getElementsByClassName("PostText Parent")[0].innerHTML = AnotherPost.value.text; if (AnotherPost.value.hasOwnProperty("embed")) { await CreateMedia(AnotherPost.value, document.getElementsByClassName("Images Parent")[0], post.reply.parent.author.did); } + // Now time to see if there are any grandparents. if (AnotherPost.value.hasOwnProperty("reply")) { var AnotherAnotherPost = await BlueskyAPI.GetRecord(AnotherPost.value.reply.parent.uri.split("/")[2], AnotherPost.value.reply.parent.uri.split("/")[3], AnotherPost.value.reply.parent.uri.split("/")[4]); + document.getElementsByClassName("Origin GrandParent")[0].innerHTML = website; + document.getElementsByClassName("Handle Parent")[0].innerHTML = post.reply.grandparentAuthor.handle; document.getElementsByClassName("PostText GrandParent")[0].innerHTML = AnotherAnotherPost.value.text; if (AnotherAnotherPost.value.hasOwnProperty("embed")) { await CreateMedia(AnotherAnotherPost.value, document.getElementsByClassName("Images GrandParent")[0], post.reply.grandparentAuthor.did); diff --git a/JS/index.js b/JS/index.js index 21b84a6..93a595c 100644 --- a/JS/index.js +++ b/JS/index.js @@ -213,6 +213,10 @@ async function PosterContainerUpdate(Direction) { } } } + // Check for a thread. + if (MastodonLoadedFeed[CurrentThing + counter].in_reply_to_id != null) { + i.getElementsByClassName("PostContent")[0].innerHTML += "This post is a thread!
"; + } // Content warning. Don't show the content unless clicked!!! if (MastodonLoadedFeed[CurrentThing + counter].spoiler_text != "") { i.getElementsByClassName("PostContent")[0].innerHTML += "WARNING: " + MastodonLoadedFeed[CurrentThing + counter].spoiler_text + ""; @@ -248,6 +252,10 @@ async function PosterContainerUpdate(Direction) { i.getElementsByClassName("PostContent")[0].innerHTML += "This post has a video!
"; } } + // Check for a thread. + if (BlueskyLoadedFeed[CurrentThing + counter].hasOwnProperty("reply")) { + i.getElementsByClassName("PostContent")[0].innerHTML += "This post is a thread!
"; + } // Labels if (BlueskyLoadedFeed[CurrentThing + counter].post.labels.length != 0) { i.getElementsByClassName("PostContent")[0].innerHTML += "LABELS APPLIED: "; @@ -260,12 +268,25 @@ async function PosterContainerUpdate(Direction) { } // Check for a reblog if (BlueskyLoadedFeed[CurrentThing + counter].hasOwnProperty("reason") && BlueskyLoadedFeed[CurrentThing + counter].reason.$type == "app.bsky.feed.defs#reasonRepost") { - i.getElementsByClassName("PostContent")[0].innerHTML += BlueskyLoadedFeed[CurrentThing + counter].post.record.text; i.getElementsByClassName("Username")[0].innerHTML = BlueskyLoadedFeed[CurrentThing + counter].post.author.handle + " ( R: " + BlueskyLoadedFeed[CurrentThing + counter].reason.by.handle + " )"; } else { - i.getElementsByClassName("PostContent")[0].innerHTML += BlueskyLoadedFeed[CurrentThing + counter].post.record.text; i.getElementsByClassName("Username")[0].innerHTML = BlueskyLoadedFeed[CurrentThing + counter].post.author.handle; } + var TempText = BlueskyLoadedFeed[CurrentThing + counter].post.record.text; + if (BlueskyLoadedFeed[CurrentThing + counter].post.record.hasOwnProperty("facets")) { + for (let i of BlueskyLoadedFeed[CurrentThing + counter].post.record.facets) { + if (i.features[0].$type == "app.bsky.richtext.facet#link") { + var EmojiRegex = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu; + var EmojiObjects = TempText.match(EmojiRegex); + var SubtractNumber = 0; + if (EmojiObjects != null) { + SubtractNumber = EmojiObjects.length * 2; + } + TempText = TempText.substring(0, i.index.byteStart - SubtractNumber) + "" + TempText.substring(i.index.byteStart - SubtractNumber, i.index.byteEnd - SubtractNumber) + "" + TempText.substring(i.index.byteEnd - SubtractNumber, TempText.length - 1); + } + } + } + i.getElementsByClassName("PostContent")[0].innerHTML += TempText; break; case 2: WebsiteAPIType.push("Nothing");