34 lines
809 B
TypeScript
Raw Permalink Normal View History

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