watch, I did somethning wrong, right?

This commit is contained in:
CatAClock 2025-07-16 20:36:31 -07:00
parent 0cf3e90a7a
commit 482ada0bcd
2 changed files with 73 additions and 7 deletions

View file

@ -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) {

View file

@ -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 = "<header> <h1 class=\"Handle " + Id + "\"> " + OtherPost.account.acct + "</h1> <h2 class=\"Origin " + Id + "\"> " + website + "</h2> </header> <p class=\"PostText " + Id + "\"></p> <div class=\"Images " + Id + "\"></div> <hr/>";
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 = "<header> <h1 class=\"Handle " + Id + "\"> " + OtherPost.account.acct + "</h1> <h2 class=\"Origin " + Id + "\"> " + website + "</h2> </header> <p class=\"PostText " + Id + "\"></p> <div class=\"Images " + Id + "\"></div> <hr/>";
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 = "<header> <h1 class=\"Handle " + Id + "\"> " + OtherPost.author.handle + "</h1> <h2 class=\"Origin " + Id + "\"> " + website + "</h2> </header> <p class=\"PostText " + Id + "\"></p> <div class=\"Images " + Id + "\"></div> <hr/>";
@ -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 = "<header> <h1 class=\"Handle " + Id + "\"> " + OtherPost.author.handle + "</h1> <h2 class=\"Origin " + Id + "\"> " + website + "</h2> </header> <p class=\"PostText " + Id + "\"></p> <div class=\"Images " + Id + "\"></div> <hr/>";
document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend", ShitHTML);
Text = BlueskyAPI.ApplyFacets(OtherPost.record, OtherPost.record.text);
Text = Text.replace(/\r?\n|\r/g, "<br/>");
// 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) {