Optimize & fix

This commit is contained in:
CatAClock 2025-07-17 19:57:15 -07:00
parent 764c626ae8
commit 7602985f7a

View file

@ -19,6 +19,14 @@ let post = JSON.parse(localStorage.getItem("post"));
let ThreadedPost = [];
document.getElementsByClassName("Origin")[0].innerHTML = website;
// Other post stuff.
for (let i of document.getElementsByClassName("Handle")) {
i.onclick = (event) => {
window.location.href = "/account?website=" + website;
}
}
GetPost();
// Fixes a bug where the interpreter sucks ass.
@ -63,15 +71,6 @@ Reply.onclick = (event) => {
window.location.href = "/post?website=" + website;
}
// Other post stuff.
for (let i of document.getElementsByClassName("Regular")) {
i.onclick = (event) => {
if (i.classList.contains("Handle")) {
window.location.href = "/account?website=" + website;
}
}
}
// Threads are the thing above the post you clicked.
async function SetThreadPost(element, i) {
if (website == "Mastodon") {
@ -114,7 +113,7 @@ async function GetPost() {
let NumberOfThreads = 0;
let TemporaryPost = post;
while (TemporaryPost.in_reply_to_id != null) {
TemporaryPost = await MastodonThreadFunction(NumberOfThreads, TemporaryPost.in_reply_to_id);
TemporaryPost = await MastodonOtherFunction(NumberOfThreads, TemporaryPost.in_reply_to_id, true);
ThreadedPost.push(TemporaryPost);
// Any posts? Give them the thing :3
for (let i of document.getElementsByClassName(NumberOfThreads)) {
@ -128,7 +127,7 @@ async function GetPost() {
// Replies, anyone?
let Context = await MastodonAPI.GetContexts(post.id);
for (let i of Context.descendants) {
TemporaryPost = await MastodonReplyFunction(NumberOfThreads, i);
TemporaryPost = await MastodonOtherFunction(NumberOfThreads, i, false);
ThreadedPost.push(TemporaryPost);
// Any posts? Give them the thing :3
for (let j of document.getElementsByClassName(NumberOfThreads)) {
@ -171,7 +170,7 @@ async function GetPost() {
let NumberOfThreads = 0;
let TemporaryPost = post;
while (TemporaryPost.hasOwnProperty("reply")) {
TemporaryPost = await BlueskyThreadFunction(NumberOfThreads, TemporaryPost.reply.parent);
TemporaryPost = await BlueskyOtherFunction(NumberOfThreads, TemporaryPost.reply.parent, true);
ThreadedPost.push(TemporaryPost);
// Any posts? Give them the thing :3
for (let i of document.getElementsByClassName(NumberOfThreads)) {
@ -185,7 +184,7 @@ async function GetPost() {
// Replies, anyone?
let Context = await BlueskyAPI.GetPostThread(post.post.uri);
for (let i of Context.thread.replies) {
TemporaryPost = await BlueskyReplyFunction(NumberOfThreads, i.post);
TemporaryPost = await BlueskyOtherFunction(NumberOfThreads, i.post, false);
ThreadedPost.push(TemporaryPost);
// Any posts? Give them the thing :3
for (let j of document.getElementsByClassName(NumberOfThreads)) {
@ -202,8 +201,13 @@ async function GetPost() {
}
// 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);
async function MastodonOtherFunction(Id, post, IsThread) {
let OtherPost;
if (IsThread == true) {
OtherPost = await MastodonAPI.GetStatus(post);
} else {
OtherPost = 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);
if (OtherPost.spoiler_text != "") {
@ -219,54 +223,16 @@ async function MastodonThreadFunction(Id, post) {
return OtherPost;
}
async function MastodonReplyFunction(Id, post) {
let ShitHTML = "<header> <h1 class=\"Handle " + Id + "\"> " + post.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 (post.spoiler_text != "") {
document.getElementsByClassName("PostText " + Id)[0].innerHTML = "WARNING: " + post.spoiler_text;
} else {
document.getElementsByClassName("PostText " + Id)[0].innerHTML = post.content;
if (post.media_attachments.length != 0) {
for (let i of post.media_attachments) {
ApplyMedia(i, document.getElementsByClassName("Images " + Id));
}
}
}
return post;
}
// Because of repeat code, we can put it into it's own function. It grabs posts "above" it.
async function BlueskyThreadFunction(Id, post) {
async function BlueskyOtherFunction(Id, post, IsThread) {
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/>";
if (IsThread == true) {
document.getElementsByTagName("body")[0].insertAdjacentHTML("afterbegin", 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;
}
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