90 lines
2.4 KiB
JavaScript
90 lines
2.4 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);
|
|
SetFollow();
|
|
} else if (website == "Bluesky") {
|
|
|
|
}
|
|
}
|
|
|
|
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);
|
|
SetBlock();
|
|
} else if (website == "Bluesky") {
|
|
|
|
}
|
|
}
|
|
|
|
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);
|
|
} else {
|
|
AccountName.innerHTML = post.account.username;
|
|
AccountDescription.innerHTML = post.account.note;
|
|
AccountImage.setAttribute("src", post.account.avatar);
|
|
}
|
|
} else if (website == "Bluesky") {
|
|
|
|
}
|
|
}
|