34 lines
809 B
TypeScript
Raw Normal View History

2019-11-18 11:04:13 +09:00
import requestIdleCallback from "scripts/Utils/requestIdleCallback"
2018-04-02 07:34:16 +02:00
import AnimeNotifier from "../AnimeNotifier"
2017-10-17 11:27:15 +02:00
// Load
export function load(arn: AnimeNotifier, element: HTMLElement) {
2019-11-17 18:25:14 +09:00
const url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
2019-04-22 15:05:16 +09:00
if(!url) {
arn.statusMessage.showError("Link doesn't have a target")
return
}
2017-10-17 11:27:15 +02:00
arn.app.load(url)
}
// Diff
2019-04-22 15:02:51 +09:00
export async function diff(arn: AnimeNotifier, element: HTMLElement) {
2019-11-17 18:25:14 +09:00
const url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
2019-04-22 15:05:16 +09:00
if(!url) {
arn.statusMessage.showError("Link doesn't have a target")
return
}
2019-04-22 15:02:51 +09:00
try {
await arn.diff(url)
2017-11-10 08:41:45 +01:00
// Avoid instant layout thrashing
2018-04-02 07:34:16 +02:00
requestIdleCallback(() => arn.scrollTo(element))
2019-04-22 15:02:51 +09:00
} catch(err) {
arn.statusMessage.showError(err)
}
2019-11-17 18:44:30 +09:00
}