2019-11-18 11:04:13 +09:00

34 lines
809 B
TypeScript

import requestIdleCallback from "scripts/Utils/requestIdleCallback"
import AnimeNotifier from "../AnimeNotifier"
// Load
export function load(arn: AnimeNotifier, element: HTMLElement) {
const url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
if(!url) {
arn.statusMessage.showError("Link doesn't have a target")
return
}
arn.app.load(url)
}
// Diff
export async function diff(arn: AnimeNotifier, element: HTMLElement) {
const url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
if(!url) {
arn.statusMessage.showError("Link doesn't have a target")
return
}
try {
await arn.diff(url)
// Avoid instant layout thrashing
requestIdleCallback(() => arn.scrollTo(element))
} catch(err) {
arn.statusMessage.showError(err)
}
}