Threads and a few bug fixes with links

This commit is contained in:
CatAClock 2025-05-22 15:52:19 -07:00
parent 81ba37fcdf
commit 5dbc2a2b44
3 changed files with 61 additions and 10 deletions

View file

@ -13,10 +13,18 @@
<body style="margin: 0px; text-align: center;">
<!-- Grandparent is a reply post above the reply post above the regular, clicked post. -->
<header>
<h1 class="Handle GrandParent"></h1>
<h2 class="Origin GrandParent"></h2>
</header>
<p class="PostText GrandParent"></p>
<div class="Images GrandParent"></div>
<hr/>
<!-- Parent is a reply post above the regular, clicked post. -->
<header>
<h1 class="Handle Parent"></h1>
<h2 class="Origin Parent"></h2>
</header>
<p class="PostText Parent"></p>
<div class="Images Parent"></div>
<hr/>

View file

@ -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) + "<a href='" + i.features[0].uri + "'>" + Text.substring(i.index.byteStart - SubtractNumber, i.index.byteEnd - SubtractNumber) + "</a>" + 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);

View file

@ -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!<br/>";
}
// Content warning. Don't show the content unless clicked!!!
if (MastodonLoadedFeed[CurrentThing + counter].spoiler_text != "") {
i.getElementsByClassName("PostContent")[0].innerHTML += "<b>WARNING: " + MastodonLoadedFeed[CurrentThing + counter].spoiler_text + "</b>";
@ -248,6 +252,10 @@ async function PosterContainerUpdate(Direction) {
i.getElementsByClassName("PostContent")[0].innerHTML += "This post has a video!<br/>";
}
}
// Check for a thread.
if (BlueskyLoadedFeed[CurrentThing + counter].hasOwnProperty("reply")) {
i.getElementsByClassName("PostContent")[0].innerHTML += "This post is a thread!<br/>";
}
// Labels
if (BlueskyLoadedFeed[CurrentThing + counter].post.labels.length != 0) {
i.getElementsByClassName("PostContent")[0].innerHTML += "<b>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) + "<a href='" + i.features[0].uri + "'>" + TempText.substring(i.index.byteStart - SubtractNumber, i.index.byteEnd - SubtractNumber) + "</a>" + TempText.substring(i.index.byteEnd - SubtractNumber, TempText.length - 1);
}
}
}
i.getElementsByClassName("PostContent")[0].innerHTML += TempText;
break;
case 2:
WebsiteAPIType.push("Nothing");