diff --git a/src/HTTP/JS/MastodonAPI.js b/src/HTTP/JS/MastodonAPI.js index 0680fc4..b950692 100644 --- a/src/HTTP/JS/MastodonAPI.js +++ b/src/HTTP/JS/MastodonAPI.js @@ -93,6 +93,14 @@ export async function GetStatus(ID) { .then((response) => response.json()); } +export async function GetContexts(ID) { + if (Token == null || TokenType == null) { + return ""; + } + return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses/" + ID + "/context", {method: "GET", headers: {"Authorization": TokenType + " " + Token}}) + .then((response) => response.json()); +} + // Get your own account by verifying your credentials. export async function GetOwnAccount() { if (Token == null || TokenType == null) { diff --git a/src/HTTP/JS/expanded.js b/src/HTTP/JS/expanded.js index 5325dfb..801fa97 100644 --- a/src/HTTP/JS/expanded.js +++ b/src/HTTP/JS/expanded.js @@ -114,9 +114,9 @@ async function GetPost() { let NumberOfThreads = 0; let TemporaryPost = post; while (TemporaryPost.in_reply_to_id != null) { - TemporaryPost = await MastodonReplylFunction(NumberOfThreads, TemporaryPost.in_reply_to_id); + TemporaryPost = await MastodonThreadFunction(NumberOfThreads, TemporaryPost.in_reply_to_id); ThreadedPost.push(TemporaryPost); - // Any replies? Give them the thing :3 + // Any posts? Give them the thing :3 for (let i of document.getElementsByClassName(NumberOfThreads)) { let TempID = NumberOfThreads; i.onclick = (event) => { @@ -125,6 +125,20 @@ async function GetPost() { } NumberOfThreads += 1; } + // Replies, anyone? + let Context = await GetContexts(post.id); + for (let i of Context.descendants) { + TemporaryPost = await MastodonReplyFunction(NumberOfThreads, i); + ThreadedPost.push(TemporaryPost); + // Any posts? Give them the thing :3 + for (let j of document.getElementsByClassName(NumberOfThreads)) { + let TempID = NumberOfThreads; + j.onclick = (event) => { + SetThreadPost(ThreadedPost[TempID], j); + } + } + NumberOfThreads += 1; + } } else if (website == "Bluesky") { // Check for a reblog. if (post.hasOwnProperty("reason") && post.reason.$type == "app.bsky.feed.defs#reasonRepost") { @@ -157,9 +171,9 @@ async function GetPost() { let NumberOfThreads = 0; let TemporaryPost = post; while (TemporaryPost.hasOwnProperty("reply")) { - TemporaryPost = await BlueskyReplyFunction(NumberOfThreads, TemporaryPost.reply.parent); + TemporaryPost = await BlueskyThreadFunction(NumberOfThreads, TemporaryPost.reply.parent); ThreadedPost.push(TemporaryPost); - // Any replies? Give them the thing :3 + // Any posts? Give them the thing :3 for (let i of document.getElementsByClassName(NumberOfThreads)) { let TempID = NumberOfThreads; i.onclick = (event) => { @@ -173,8 +187,8 @@ async function GetPost() { } } -// Because of repeat code, we can put it into it's own function. Hell, more of a thread can be added later. -async function MastodonReplylFunction(Id, post) { +// Because of repeat code, we can put it into it's own function. It grabs posts "above" it. +async function MastodonThreadFunction(Id, post) { let OtherPost = await MastodonAPI.GetStatus(post); let ShitHTML = "

" + OtherPost.account.acct + "

" + website + "


"; document.getElementsByTagName("body")[0].insertAdjacentHTML("afterbegin", ShitHTML); @@ -191,7 +205,25 @@ async function MastodonReplylFunction(Id, post) { return OtherPost; } -async function BlueskyReplyFunction(Id, post) { +async function MastodonReplyFunction(Id, post) { + let OtherPost = await MastodonAPI.GetStatus(post); + let ShitHTML = "

" + OtherPost.account.acct + "

" + website + "


"; + document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend", ShitHTML); + if (OtherPost.spoiler_text != "") { + document.getElementsByClassName("PostText " + Id)[0].innerHTML = "WARNING: " + OtherPost.spoiler_text; + } else { + document.getElementsByClassName("PostText " + Id)[0].innerHTML = OtherPost.content; + if (OtherPost.media_attachments.length != 0) { + for (let i of OtherPost.media_attachments) { + ApplyMedia(i, document.getElementsByClassName("Images " + Id)); + } + } + } + return OtherPost; +} + +// Because of repeat code, we can put it into it's own function. It grabs posts "above" it. +async function BlueskyThreadFunction(Id, post) { let OtherPost = await BlueskyAPI.GetPosts([post.uri]); OtherPost = OtherPost.posts[0]; let ShitHTML = "

" + OtherPost.author.handle + "

" + website + "


"; @@ -217,6 +249,32 @@ async function BlueskyReplyFunction(Id, post) { return OtherPost; } +async function BlueskyReplyFunction(Id, post) { + let OtherPost = await BlueskyAPI.GetPosts([post.uri]); + OtherPost = OtherPost.posts[0]; + let ShitHTML = "

" + OtherPost.author.handle + "

" + website + "


"; + document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend", ShitHTML); + Text = BlueskyAPI.ApplyFacets(OtherPost.record, OtherPost.record.text); + Text = Text.replace(/\r?\n|\r/g, "
"); + // Sensitive topic :3 + if (OtherPost.record.hasOwnProperty("labels") && OtherPost.record.labels.length != 0) { + document.getElementsByClassName("PostText " + Id)[0].innerHTML = "LABELS APPLIED: "; + for (let lab of OtherPost.value.labels.values) { + document.getElementsByClassName("PostText " + Id)[0].innerHTML += lab.val + " "; + } + } else { + document.getElementsByClassName("PostText " + Id)[0].innerHTML = Text; + if (OtherPost.record.hasOwnProperty("embed")) { + ApplyMedia(OtherPost.record.embed, document.getElementsByClassName("Images " + Id)[0], OtherPost.author.did); + } + } + // Get the reply and make it make sense. + if (OtherPost.record.hasOwnProperty("reply")) { + OtherPost.reply = OtherPost.record.reply; + } + return OtherPost; +} + // Applyers. Essentially applies a thing to an operation. // Finds any associated media and applies it to the post. async function ApplyMedia(Media, Element, Author = undefined) {