new stupid facet

This commit is contained in:
CatAClock 2025-05-23 13:23:53 -07:00
parent a41a35e6e1
commit cb5f53ded8

View file

@ -106,7 +106,7 @@ async function GetPost() {
document.getElementsByClassName("PostText Regular")[0].innerHTML = Text;
// Show the image if it exists.
if (post.post.record.hasOwnProperty("embed")) {
await ApplyMedia(post.post.record, document.getElementsByClassName("Images Regular")[0], post.post.author.did);
await ApplyMedia(post.post.record.embed, document.getElementsByClassName("Images Regular")[0], post.post.author.did);
}
// We don't need to update the post with new information. The repos are seperate.
// Set the texts. It's opposite because "setting" causes it to switch.
@ -129,7 +129,7 @@ async function GetPost() {
Text = Text.replace(/\r?\n|\r/g, "<br/>");
document.getElementsByClassName("PostText Parent")[0].innerHTML = Text;
if (AnotherPost.value.hasOwnProperty("embed")) {
await ApplyMedia(AnotherPost.value, document.getElementsByClassName("Images Parent")[0], post.reply.parent.author.did);
await ApplyMedia(AnotherPost.value.embed, document.getElementsByClassName("Images Parent")[0], post.reply.parent.author.did);
}
// Now time to see if there are any grandparents.
@ -141,7 +141,7 @@ async function GetPost() {
Text = Text.replace(/\r?\n|\r/g, "<br/>");
document.getElementsByClassName("PostText GrandParent")[0].innerHTML = Text;
if (AnotherAnotherPost.value.hasOwnProperty("embed")) {
await ApplyMedia(AnotherAnotherPost.value, document.getElementsByClassName("Images GrandParent")[0], post.reply.grandparentAuthor.did);
await ApplyMedia(AnotherAnotherPost.value.embed, document.getElementsByClassName("Images GrandParent")[0], post.reply.grandparentAuthor.did);
}
}
}
@ -169,37 +169,49 @@ async function ApplyMedia(Media, Element, Author = undefined) {
}
}
} else if (website == "Bluesky") {
if (Media.embed.$type == "app.bsky.embed.record") {
var Texty = await BlueskyAPI.GetPosts([Media.embed.record.uri]);
// Record and media embed; They are from seperate posts.
if (Media.$type == "app.bsky.embed.recordWithMedia") {
await BlueskyBlobEmbed(Media.media, Element, Author);
var Texty = await BlueskyAPI.GetPosts([Media.record.record.uri]);
var Text = BlueskyAPI.ApplyFacets(Texty.posts[0].record, Texty.posts[0].record.text);
Text = Text.replace(/\r?\n|\r/g, "<br/>");
Element.innerHTML += "<p class='Embed'>" + Text + "</p><br/>";
if (Texty.posts[0].record.embed.$type == "app.bsky.embed.images") {
for (let i of Texty.posts[0].record.embed.images) {
var Blobby = await BlueskyAPI.GetBlob(Texty.posts[0].author.did, i.image.ref.$link);
var ObjectURL = URL.createObjectURL(Blobby);
Element.innerHTML += "<img class='Embed' src=" + ObjectURL + " alt='" + EscapeRegExp(i.alt) + "'/>";
}
} else if (Texty.posts[0].record.embed.$type == "app.bsky.embed.video") {
var Blobby = await BlueskyAPI.GetBlob(Texty.posts[0].author.did, Texty.posts[0].record.embed.video.ref.$link);
var ObjectURL = URL.createObjectURL(Blobby);
Element.innerHTML += "<video class='Embed' controls src=" + ObjectURL + "></video>";
// To stop confusion: this is for the RECORD EMBED! It gets an image from the record embed and puts it there.
if (Texty.posts[0].record.embed.$type == "app.bsky.embed.images" || Texty.posts[0].record.embed.$type == "app.bsky.embed.video") {
await BlueskyBlobEmbed(Texty.posts[0].record.embed, Element, Author);
}
// It's not an embed, continue...
} else if (Media.embed.$type == "app.bsky.embed.images") {
for (let i of Media.embed.images) {
var Blobby = await BlueskyAPI.GetBlob(Author, i.image.ref.$link);
var ObjectURL = URL.createObjectURL(Blobby);
Element.innerHTML += "<img src=" + ObjectURL + " alt='" + EscapeRegExp(i.alt) + "'/>";
// Just a record on it's own.
} else if (Media.$type == "app.bsky.embed.record") {
var Texty = await BlueskyAPI.GetPosts([Media.record.uri]);
var Text = BlueskyAPI.ApplyFacets(Texty.posts[0].record, Texty.posts[0].record.text);
Text = Text.replace(/\r?\n|\r/g, "<br/>");
Element.innerHTML += "<p class='Embed'>" + Text + "</p><br/>";
if (Texty.posts[0].record.embed.$type == "app.bsky.embed.images" || Texty.posts[0].record.embed.$type == "app.bsky.embed.video") {
await BlueskyBlobEmbed(Texty.posts[0].record.embed, Element, Author);
}
} else if (Media.embed.$type == "app.bsky.embed.video") {
var Blobby = await BlueskyAPI.GetBlob(Author, Media.embed.video.ref.$link);
var ObjectURL = URL.createObjectURL(Blobby);
Element.innerHTML += "<video controls src=" + ObjectURL + "></video>";
// Image on it's own
} else if (Media.$type == "app.bsky.embed.images" || Media.$type == "app.bsky.embed.video") {
await BlueskyBlobEmbed(Media, Element, Author);
}
}
}
// Fucking hell.
async function BlueskyBlobEmbed(Blob, Element, Author) {
if (Blob.$type == "app.bsky.embed.images") {
for (let i of Blob.images) {
var Blobby = await BlueskyAPI.GetBlob(Author, i.image.ref.$link);
var ObjectURL = URL.createObjectURL(Blobby);
Element.innerHTML += "<img src=" + ObjectURL + " alt='" + EscapeRegExp(i.alt) + "'/>";
}
// Video embed.
} else if (Blob.$type == "app.bsky.embed.video") {
var Blobby = await BlueskyAPI.GetBlob(Author, Blob.video.ref.$link);
var ObjectURL = URL.createObjectURL(Blobby);
Element.innerHTML += "<video controls src=" + ObjectURL + "></video>";
}
}
// Setters
function SetFavorite() {
FavoriteFlipper = !(FavoriteFlipper);