fixed more of the facets.
This commit is contained in:
parent
456bd86379
commit
a41a35e6e1
3 changed files with 61 additions and 67 deletions
|
@ -218,6 +218,45 @@ export async function CreateRecord(Repo, Collection, Record, RKey) {
|
|||
return body;
|
||||
}
|
||||
|
||||
// Applyers
|
||||
export function ApplyFacets(record, text) {
|
||||
var StringArray = [];
|
||||
var SplitAreas = [0];
|
||||
var Hrefs = [];
|
||||
var TempText = "";
|
||||
if (record.hasOwnProperty("facets")) {
|
||||
// First, append split areas.
|
||||
for (let i of record.facets) {
|
||||
if (i.features[0].$type == "app.bsky.richtext.facet#link") {
|
||||
SplitAreas.push(i.index.byteStart);
|
||||
SplitAreas.push(i.index.byteEnd);
|
||||
Hrefs.push(i.features[0].uri);
|
||||
Hrefs.push("");
|
||||
}
|
||||
}
|
||||
// Last minute append.
|
||||
SplitAreas.push(text.length);
|
||||
// Remove emoji regex
|
||||
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;
|
||||
}
|
||||
// Now we split the string
|
||||
for (let i = 1; i < SplitAreas.length; i++) {
|
||||
StringArray.push(text.slice(SplitAreas[i - 1] - SubtractNumber, SplitAreas[i] - SubtractNumber));
|
||||
}
|
||||
// Finally, we append the string with <a>
|
||||
for (let i = 1; i < StringArray.length; i += 2) {
|
||||
TempText += StringArray[i - 1] + "<a href='" + Hrefs[i - 1] + "'>" + StringArray[i] + "</a>";
|
||||
}
|
||||
}
|
||||
if (TempText == "") {
|
||||
return text;
|
||||
}return TempText;
|
||||
}
|
||||
|
||||
// Deleters
|
||||
// Removes a record. Can be a like, a repost, a post, etc.
|
||||
export async function DeleteRecord(Repo, Collection, RKey) {
|
||||
|
|
|
@ -100,7 +100,7 @@ async function GetPost() {
|
|||
document.getElementsByClassName("Handle Regular")[0].innerHTML = post.post.author.handle;
|
||||
}
|
||||
// Text. This will be modified later.
|
||||
var Text = ApplyFacets(post.post.record, post.post.record.text);
|
||||
var Text = await BlueskyAPI.ApplyFacets(post.post.record, post.post.record.text);
|
||||
// Place the text.
|
||||
Text = Text.replace(/\r?\n|\r/g, "<br/>");
|
||||
document.getElementsByClassName("PostText Regular")[0].innerHTML = Text;
|
||||
|
@ -125,7 +125,7 @@ async function GetPost() {
|
|||
var AnotherPost = await BlueskyAPI.GetRecord(post.reply.parent.uri.split("/")[2], post.reply.parent.uri.split("/")[3], post.reply.parent.uri.split("/")[4]);
|
||||
document.getElementsByClassName("Origin Parent")[0].innerHTML = website;
|
||||
document.getElementsByClassName("Handle Parent")[0].innerHTML = post.reply.parent.author.handle;
|
||||
Text = ApplyFacets(AnotherPost.value, AnotherPost.value.text);
|
||||
Text = BlueskyAPI.ApplyFacets(AnotherPost.value, AnotherPost.value.text);
|
||||
Text = Text.replace(/\r?\n|\r/g, "<br/>");
|
||||
document.getElementsByClassName("PostText Parent")[0].innerHTML = Text;
|
||||
if (AnotherPost.value.hasOwnProperty("embed")) {
|
||||
|
@ -137,7 +137,7 @@ async function GetPost() {
|
|||
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 GrandParent")[0].innerHTML = post.reply.grandparentAuthor.handle;
|
||||
Text = ApplyFacets(AnotherAnotherPost.value, AnotherAnotherPost.value.text);
|
||||
Text = BlueskyAPI.ApplyFacets(AnotherAnotherPost.value, AnotherAnotherPost.value.text);
|
||||
Text = Text.replace(/\r?\n|\r/g, "<br/>");
|
||||
document.getElementsByClassName("PostText GrandParent")[0].innerHTML = Text;
|
||||
if (AnotherAnotherPost.value.hasOwnProperty("embed")) {
|
||||
|
@ -157,28 +157,28 @@ async function ApplyMedia(Media, Element, Author = undefined) {
|
|||
if (website == "Mastodon") {
|
||||
if (Media.type == "image") {
|
||||
if (Media.remote_url == null) {
|
||||
Element.innerHTML += "<img src=" + Media.url + " alt='" + Media.description + "'/>";
|
||||
Element.innerHTML += "<img src=" + Media.url + " alt='" + EscapeRegExp(Media.description) + "'/>";
|
||||
} else {
|
||||
Element.innerHTML += "<img src=" + Media.remote_url + " alt='" + Media.description + "'/>";
|
||||
Element.innerHTML += "<img src=" + Media.remote_url + " alt='" + EscapeRegExp(Media.description) + "'/>";
|
||||
}
|
||||
} else if (Media.type == "video") {
|
||||
if (Media.remote_url == null) {
|
||||
Element.innerHTML += "<video controls src=" + Media.url + " alt='" + Media.description + "'></video>";
|
||||
Element.innerHTML += "<video controls src=" + Media.url + " alt='" + EscapeRegExp(Media.description) + "'></video>";
|
||||
} else {
|
||||
Element.innerHTML += "<video controls src=" + Media.remote_url + " alt='" + Media.description + "'></video>";
|
||||
Element.innerHTML += "<video controls src=" + Media.remote_url + " alt='" + EscapeRegExp(Media.description) + "'></video>";
|
||||
}
|
||||
}
|
||||
} else if (website == "Bluesky") {
|
||||
if (Media.embed.$type == "app.bsky.embed.record") {
|
||||
var Texty = await BlueskyAPI.GetPosts([Media.embed.record.uri]);
|
||||
var Text = ApplyFacets(Texty.posts[0].record, Texty.posts[0].record.text);
|
||||
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='" + i.alt + "'/>";
|
||||
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);
|
||||
|
@ -190,7 +190,7 @@ async function ApplyMedia(Media, Element, Author = undefined) {
|
|||
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='" + i.alt + "'/>";
|
||||
Element.innerHTML += "<img src=" + ObjectURL + " alt='" + EscapeRegExp(i.alt) + "'/>";
|
||||
}
|
||||
} else if (Media.embed.$type == "app.bsky.embed.video") {
|
||||
var Blobby = await BlueskyAPI.GetBlob(Author, Media.embed.video.ref.$link);
|
||||
|
@ -200,47 +200,6 @@ async function ApplyMedia(Media, Element, Author = undefined) {
|
|||
}
|
||||
}
|
||||
|
||||
// Applies the necessary facets to the text.
|
||||
function ApplyFacets(record, text) {
|
||||
var StringArray = [];
|
||||
var SplitAreas = [0];
|
||||
var Hrefs = [];
|
||||
var TempText = "";
|
||||
if (record.hasOwnProperty("facets")) {
|
||||
// First, append split areas.
|
||||
for (let i of record.facets) {
|
||||
if (i.features[0].$type == "app.bsky.richtext.facet#link") {
|
||||
SplitAreas.push(i.index.byteStart);
|
||||
SplitAreas.push(i.index.byteEnd);
|
||||
Hrefs.push(i.features[0].uri);
|
||||
Hrefs.push("");
|
||||
}
|
||||
}
|
||||
// Last minute append.
|
||||
SplitAreas.push(text.length);
|
||||
// Remove emoji regex
|
||||
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;
|
||||
}
|
||||
// Now we split the string
|
||||
for (let i = 1; i < SplitAreas.length; i++) {
|
||||
StringArray.push(text.slice(SplitAreas[i - 1] - SubtractNumber, SplitAreas[i] - SubtractNumber));
|
||||
}
|
||||
// Finally, we append the string with <a>
|
||||
for (let i = 0; i < StringArray.length; i += 2) {
|
||||
TempText += StringArray[i] + "<a href='" + Hrefs[i] + "'>" + StringArray[i + 1] + "</a>";
|
||||
}
|
||||
// Last minute append.
|
||||
TempText += StringArray[StringArray.length - 1];
|
||||
return TempText;
|
||||
} else {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
// Setters
|
||||
function SetFavorite() {
|
||||
FavoriteFlipper = !(FavoriteFlipper);
|
||||
|
@ -259,3 +218,11 @@ function SetBoost() {
|
|||
Boost.innerHTML = "Unboost...";
|
||||
}
|
||||
}
|
||||
|
||||
// Functions stolen form elsewhere
|
||||
function EscapeRegExp(text) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\$&');
|
||||
}
|
||||
|
|
20
JS/index.js
20
JS/index.js
|
@ -244,7 +244,7 @@ async function PosterContainerUpdate(Direction) {
|
|||
// check for "already seen" posts, then put it as a seen post.
|
||||
BlueskyLoadedFeed = CheckForDups(BlueskyLoadedFeed, BlueskyPostsDup, counter);
|
||||
BlueskyPostsDup.push(BlueskyLoadedFeed[counter].post.uri);
|
||||
// Check for an image
|
||||
// Check for an image.
|
||||
if (BlueskyLoadedFeed[CurrentThing + counter].post.record.hasOwnProperty("embed")) {
|
||||
if (BlueskyLoadedFeed[CurrentThing + counter].post.record.embed.$type == "app.bsky.embed.images") {
|
||||
i.getElementsByClassName("PostContent")[0].innerHTML += "This post has an image!<br/>";
|
||||
|
@ -266,26 +266,14 @@ async function PosterContainerUpdate(Direction) {
|
|||
i.getElementsByClassName("PostContent")[0].innerHTML += "</b>";
|
||||
break;
|
||||
}
|
||||
// Check for a reblog
|
||||
// Check for a reblog.
|
||||
if (BlueskyLoadedFeed[CurrentThing + counter].hasOwnProperty("reason") && BlueskyLoadedFeed[CurrentThing + counter].reason.$type == "app.bsky.feed.defs#reasonRepost") {
|
||||
i.getElementsByClassName("Username")[0].innerHTML = BlueskyLoadedFeed[CurrentThing + counter].post.author.handle + " ( R: " + BlueskyLoadedFeed[CurrentThing + counter].reason.by.handle + " )";
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Apply correct facets.
|
||||
var TempText = await BlueskyAPI.ApplyFacets(BlueskyLoadedFeed[CurrentThing + counter].post.record, BlueskyLoadedFeed[CurrentThing + counter].post.record.text);
|
||||
TempText = TempText.replace(/\r?\n|\r/g, "<br/>");
|
||||
i.getElementsByClassName("PostContent")[0].innerHTML += TempText;
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue