- Animation improvements on `Index.html`. - Reduced the amount of code (and improved readability) of the APIs. - Optimizations as well, but not that much. - Accounts are now viewable. You can also follow and block them to your heart's content (I don't know what happens when you both block and follow). - Many, many bug fixes that made it through. Reviewed-on: #40
112 lines
3.5 KiB
JavaScript
112 lines
3.5 KiB
JavaScript
import * as MastodonAPI from "./MastodonAPI.js";
|
|
import * as BlueskyAPI from "./BlueskyAPI.js";
|
|
import * as TumblrAPI from "./TumblrAPI.js";
|
|
import * as Variables from "./Variables.js";
|
|
|
|
let website = document.location.href.split("website=")[1];
|
|
let post = JSON.parse(localStorage.getItem("post"));
|
|
|
|
// HTML elements.
|
|
let AccountName = document.getElementsByClassName("Account")[0];
|
|
let AccountImage = document.getElementsByClassName("AccountImage")[0];
|
|
let AccountDescription = document.getElementsByClassName("AccountDescription")[0];
|
|
let FollowButton = document.getElementsByClassName("Follow")[0];
|
|
let BlockButton = document.getElementsByClassName("Block")[0];
|
|
|
|
// Other vars.
|
|
let Following = false;
|
|
let Blocking = false;
|
|
|
|
GetAccount();
|
|
|
|
FollowButton.onclick = (event) => {
|
|
FollowBoop();
|
|
}
|
|
|
|
async function FollowBoop() {
|
|
if (website == "Mastodon") {
|
|
let Relations = await MastodonAPI.GetRelationship(post.account.id);
|
|
await MastodonAPI.CreateFollow(post.account.id, Relations[0].following);
|
|
} else if (website == "Bluesky") {
|
|
await BlueskyAPI.CreateFollow(localStorage.getItem(Variables.BlueskyDID), post.post.author.did);
|
|
}
|
|
SetFollow();
|
|
}
|
|
|
|
function SetFollow() {
|
|
Following = !(Following);
|
|
if (Following == true) {
|
|
FollowButton.innerHTML = "Unfollow...";
|
|
} else {
|
|
FollowButton.innerHTML = "Follow!";
|
|
}
|
|
}
|
|
|
|
BlockButton.onclick = (event) => {
|
|
BlockBoop();
|
|
}
|
|
|
|
async function BlockBoop() {
|
|
if (website == "Mastodon") {
|
|
let Relations = await MastodonAPI.GetRelationship(post.account.id);
|
|
await MastodonAPI.CreateBlock(post.account.id, Relations[0].blocking);
|
|
} else if (website == "Bluesky") {
|
|
await BlueskyAPI.CreateBlock(localStorage.getItem(Variables.BlueskyDID), post.post.author.did);
|
|
}
|
|
SetBlock();
|
|
}
|
|
|
|
function SetBlock() {
|
|
Blocking = !(Blocking);
|
|
if (Blocking == true) {
|
|
BlockButton.innerHTML = "Unblock...";
|
|
} else {
|
|
BlockButton.innerHTML = "Block!";
|
|
}
|
|
}
|
|
|
|
async function GetAccount() {
|
|
if (website == "Mastodon") {
|
|
// Get the relationshop.
|
|
let Relations = await MastodonAPI.GetRelationship(post.account.id);
|
|
// Set the buttons using the relationship.
|
|
Following = !(Relations[0].following);
|
|
Blocking = !(Relations[0].blocking);
|
|
SetFollow();
|
|
SetBlock();
|
|
// Check for a reblog.
|
|
if (post.reblog != null) {
|
|
post = post.reblog;
|
|
}
|
|
AccountName.innerHTML = post.account.username;
|
|
AccountDescription.innerHTML = post.account.note;
|
|
AccountImage.setAttribute("src", post.account.avatar);
|
|
// Build the fields
|
|
let Field = "<div style=\"display: flex; justify-content: center;\">";
|
|
for (let i of post.account.fields) {
|
|
Field += "<b class=\"Entry\">" + i.name + "</b><em class=\"Exitry\">" + i.value + "</em>";
|
|
}
|
|
Field += "</div>";
|
|
AccountDescription.innerHTML += Field;
|
|
} else if (website == "Bluesky") {
|
|
// Set the relationship follows
|
|
let thing = await BlueskyAPI.GetRecord(localStorage.getItem(Variables.BlueskyDID), "app.bsky.graph.follow", post.post.author.did);
|
|
let thing2 = await BlueskyAPI.GetRecord(localStorage.getItem(Variables.BlueskyDID), "app.bsky.graph.block", post.post.author.did);
|
|
if (thing.hasOwnProperty("error") && thing.error == "RecordNotFound") {
|
|
Following = true;
|
|
} else {
|
|
Following = false;
|
|
}
|
|
if (thing2.hasOwnProperty("error") && thing2.error == "RecordNotFound") {
|
|
Blocking = true;
|
|
} else {
|
|
Blocking = false;
|
|
}
|
|
SetFollow();
|
|
SetBlock();
|
|
let account = await BlueskyAPI.GetProfile(post.post.author.did);
|
|
AccountName.innerHTML = account.handle;
|
|
AccountDescription.innerHTML = account.description;
|
|
AccountImage.setAttribute("src", account.avatar);
|
|
}
|
|
}
|