43 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-11-14 12:16:29 +00:00
import AnimeNotifier from "../AnimeNotifier"
2018-12-07 00:54:17 +00:00
import Diff from "scripts/Diff"
2018-11-14 12:16:29 +00:00
// Follow user
export async function followUser(arn: AnimeNotifier, element: HTMLElement) {
2019-04-22 06:59:08 +00:00
return updateFollow(arn, element, "You are now following")
2018-11-14 12:16:29 +00:00
}
// Unfollow user
export async function unfollowUser(arn: AnimeNotifier, element: HTMLElement) {
2019-04-22 06:59:08 +00:00
return updateFollow(arn, element, "You stopped following")
}
// Update follow
async function updateFollow(arn: AnimeNotifier, element: HTMLElement, message: string) {
2019-11-17 09:25:14 +00:00
const api = element.dataset.api
const nick = document.getElementById("nick")
2019-04-22 06:59:08 +00:00
if(!api || !nick || !nick.textContent) {
console.error("Missing data-api or invalid nick:", element)
return
}
2018-11-14 12:16:29 +00:00
try {
2019-04-22 06:59:08 +00:00
await arn.post(api)
2018-11-14 12:16:29 +00:00
await arn.reloadContent()
2019-04-22 06:59:08 +00:00
arn.statusMessage.showInfo(`${message} ${nick.textContent}.`)
2018-11-14 12:16:29 +00:00
} catch(err) {
arn.statusMessage.showError(err)
}
}
// Show more
2019-04-22 09:06:50 +00:00
export function showMore(_: AnimeNotifier, showMoreElement: HTMLElement) {
2018-11-14 12:16:29 +00:00
const elements = [...document.getElementsByClassName("show-more")]
2019-11-17 09:25:14 +00:00
for(const element of elements) {
2018-11-14 12:16:29 +00:00
Diff.mutations.queue(() => element.classList.remove("show-more"))
}
Diff.mutations.queue(() => showMoreElement.classList.add("show-more"))
2019-11-17 09:44:30 +00:00
}