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) { AccountName.innerHTML = post.reblog.account.username; AccountDescription.innerHTML = post.reblog.account.note; AccountImage.setAttribute("src", post.reblog.account.avatar); // Build the fields let Field = "
"; for (let i of post.reblog.account.fields) { Field += "" + i.name + "" + i.value + ""; } Field += "
"; AccountDescription.innerHTML += Field; } else { AccountName.innerHTML = post.account.username; AccountDescription.innerHTML = post.account.note; AccountImage.setAttribute("src", post.account.avatar); // Build the fields let Field = "
"; for (let i of post.account.fields) { Field += "" + i.name + "" + i.value + ""; } Field += "
"; 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); } }