optimization 2

This commit is contained in:
CatAClock 2025-05-25 15:38:00 -07:00
parent 4de48f76d4
commit 38201f86dd
2 changed files with 48 additions and 69 deletions

View file

@ -83,61 +83,32 @@ async function SetThreadPost(element, i) {
// Functions and things. // Functions and things.
async function GetPost() { async function GetPost() {
if (website == "Mastodon") { if (website == "Mastodon") {
// Check for a reblog.
if (post.reblog != null) {
document.getElementsByClassName("PostText Regular")[0].innerHTML = post.reblog.content;
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) {
ApplyMedia(i, document.getElementsByClassName("Images Regular")[0]);
}
}
} else {
document.getElementsByClassName("PostText Regular")[0].innerHTML = post.content;
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) {
ApplyMedia(i, document.getElementsByClassName("Images Regular")[0]);
}
}
}
// Set the texts. It's opposite because "setting" causes it to switch. // Set the texts. It's opposite because "setting" causes it to switch.
post = await MastodonAPI.GetStatus(post.id); post = await MastodonAPI.GetStatus(post.id);
FavoriteFlipper = !(post.favourited); FavoriteFlipper = !(post.favourited);
BoostFlipper = !(post.reblogged); BoostFlipper = !(post.reblogged);
SetFavorite(); SetFavorite();
SetBoost(); SetBoost();
// Check for a reblog.
if (post.reblog != null) {
document.getElementsByClassName("Handle Regular")[0].innerHTML = post.reblog.account.username + " ( R: " + post.account.username + " )";
post = post.reblog;
} else {
document.getElementsByClassName("Handle Regular")[0].innerHTML = post.account.username;
}
document.getElementsByClassName("PostText Regular")[0].innerHTML = post.content;
// Show the image if it exists.
if (post.media_attachments.length != 0) {
for (let i of post.media_attachments) {
ApplyMedia(i, document.getElementsByClassName("Images Regular")[0]);
}
}
// Now time to see if there are any parents // Now time to see if there are any parents
if (post.in_reply_to_id != null) { if (post.in_reply_to_id != null) {
Parentpost = await MastodonAPI.GetStatus(post.in_reply_to_id); let ParentPost = await MastodonReplylFunction("Parent", post.in_reply_to_id);
document.getElementsByClassName("Origin Parent")[0].innerHTML = website;
document.getElementsByClassName("Handle Parent")[0].innerHTML = Parentpost.account.username;
if (Parentpost.spoiler_text != "") {
document.getElementsByClassName("PostText Parent")[0].innerHTML = "WARNING: " + Parentpost.spoiler_text;
} else {
document.getElementsByClassName("PostText Parent")[0].innerHTML = Parentpost.content;
}
if (Parentpost.media_attachments.length != 0) {
for (let i of Parentpost.media_attachments) {
ApplyMedia(i, document.getElementsByClassName("Images Parent")[0]);
}
}
// Now time to see if there are any grandparents // Now time to see if there are any grandparents
if (Parentpost.in_reply_to_id != null) { if (ParentPost == undefined && ParentPost.in_reply_to_id != null) {
GrandParentpost = await MastodonAPI.GetStatus(Parentpost.in_reply_to_id); MastodonReplylFunction("GrandParent", ParentPost.in_reply_to_id);
document.getElementsByClassName("Origin GrandParent")[0].innerHTML = website;
document.getElementsByClassName("Handle GrandParent")[0].innerHTML = GrandParentpost.account.username;
if (GrandParentpost.spoiler_text != "") {
document.getElementsByClassName("PostText GrandParent")[0].innerHTML = "WARNING: " + GrandParentpost.spoiler_text;
} else {
document.getElementsByClassName("PostText GrandParent")[0].innerHTML = GrandParentpost.content;
}
if (GrandParentpost.media_attachments.length != 0) {
for (let i of GrandParentpost.media_attachments) {
ApplyMedia(i, document.getElementsByClassName("Images GrandParent")[0]);
}
}
} }
} }
} else if (website == "Bluesky") { } else if (website == "Bluesky") {
@ -214,6 +185,24 @@ 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(ClassName, post) {
let OtherPost = await MastodonAPI.GetStatus(post);
document.getElementsByClassName("Origin " + ClassName)[0].innerHTML = website;
document.getElementsByClassName("Handle " + ClassName)[0].innerHTML = OtherPost.account.username;
if (OtherPost.spoiler_text != "") {
document.getElementsByClassName("PostText " + ClassName)[0].innerHTML = "WARNING: " + OtherPost.spoiler_text;
} else {
document.getElementsByClassName("PostText " + ClassName)[0].innerHTML = OtherPost.content;
}
if (OtherPost.media_attachments.length != 0) {
for (let i of OtherPost.media_attachments) {
ApplyMedia(i, document.getElementsByClassName("Images " + ClassName)[0]);
}
}
return OtherPost;
}
// Applyers. Essentially applies a thing to an operation. // Applyers. Essentially applies a thing to an operation.
// Finds any associated media and applies it to the post. // Finds any associated media and applies it to the post.
async function ApplyMedia(Media, Element, Author = undefined) { async function ApplyMedia(Media, Element, Author = undefined) {

View file

@ -221,22 +221,19 @@ async function PosterContainerUpdate(Direction) {
} }
MastodonLoadedFeed = MastodonLoadedFeed.concat(TempFeed); MastodonLoadedFeed = MastodonLoadedFeed.concat(TempFeed);
} }
// Check for images. Reblog roundabout fix included. // put the reblog into the regular post; Make changes as necessary.
if (MastodonLoadedFeed[CurrentThing + counter].reblog != null) { if (MastodonLoadedFeed[CurrentThing + counter].reblog != null) {
if (MastodonLoadedFeed[CurrentThing + counter].reblog.media_attachments.length != 0) { i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].reblog.account.username + " ( R: " + MastodonLoadedFeed[CurrentThing + counter].account.username + " )";
if (MastodonLoadedFeed[CurrentThing + counter].reblog.media_attachments[0].type == "image") { MastodonLoadedFeed[CurrentThing + counter] = MastodonLoadedFeed[CurrentThing + counter].reblog;
i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!<br/>";
} else if (MastodonLoadedFeed[CurrentThing + counter].reblog.media_attachments[0].type == "video" || MastodonLoadedFeed[CurrentThing + counter].reblog.media_attachments[0].type == "gifv") {
i.getElementsByClassName("PostContent")[0].innerHTML += "This post has a video!<br/>";
}
}
} else { } else {
if (MastodonLoadedFeed[CurrentThing + counter].media_attachments.length != 0) { i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].account.username
if (MastodonLoadedFeed[CurrentThing + counter].media_attachments[0].type == "image") { }
i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!<br/>"; // Check for images.
} else if (MastodonLoadedFeed[CurrentThing + counter].media_attachments[0].type == "video" || MastodonLoadedFeed[CurrentThing + counter].media_attachments[0].type == "gifv") { if (MastodonLoadedFeed[CurrentThing + counter].media_attachments.length != 0) {
i.getElementsByClassName("PostContent")[0].innerHTML += "This post has a video!<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" || MastodonLoadedFeed[CurrentThing + counter].media_attachments[0].type == "gifv") {
i.getElementsByClassName("PostContent")[0].innerHTML += "This post has a video!<br/>";
} }
} }
// Check for a thread. // Check for a thread.
@ -249,14 +246,7 @@ async function PosterContainerUpdate(Direction) {
i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].account.username; i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].account.username;
break; break;
} }
// Check for a reblog. i.getElementsByClassName("PostContent")[0].innerHTML += MastodonLoadedFeed[CurrentThing + counter].content;
if (MastodonLoadedFeed[CurrentThing + counter].reblog != null) {
i.getElementsByClassName("PostContent")[0].innerHTML += MastodonLoadedFeed[CurrentThing + counter].reblog.content;
i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].reblog.account.username + " ( R: " + MastodonLoadedFeed[CurrentThing + counter].account.username + " )";
} else {
i.getElementsByClassName("PostContent")[0].innerHTML += MastodonLoadedFeed[CurrentThing + counter].content;
i.getElementsByClassName("Username")[0].innerHTML = MastodonLoadedFeed[CurrentThing + counter].account.username;
}
break; break;
// Bsky // Bsky
case 1: case 1:
@ -326,7 +316,7 @@ function CheckForDups(Timeline, DupeArray, counter) {
for (let j of DupeArray) { for (let j of DupeArray) {
if (j == Timeline[counter].post.uri) { if (j == Timeline[counter].post.uri) {
Timeline.splice(counter, 1); Timeline.splice(counter, 1);
console.log("Culled a duplicate post.") console.log("Culled a duplicate post.");
Timeline = CheckForDups(Timeline, DupeArray, counter); Timeline = CheckForDups(Timeline, DupeArray, counter);
} }
} }