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 AlternateAccountName = document.getElementsByClassName("Account")[1]; let AlternateAccountImage = document.getElementsByClassName("AccountImage")[1]; let AlternateAccountDescription = document.getElementsByClassName("AccountDescription")[1]; let FollowButton = document.getElementsByClassName("Follow")[0]; let BlockButton = document.getElementsByClassName("Block")[0]; let AccountPosts = document.getElementsByClassName("Posts")[0]; // Other vars. let Following = false; let Blocking = false; // SPAWN GetAccount(); // The interaction is given to another function for async. 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(); } // Extra thing for the frontend to say "hey I am the follow meister". function SetFollow() { Following = !(Following); if (Following == true) { FollowButton.innerHTML = "Unfollow..."; } else { FollowButton.innerHTML = "Follow!"; } } // The interaction is given to another function for async. 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(); } // Extra thing for the frontend to say "hey I am the block meister". 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 = "