2018-04-02 05:34:16 +00:00
|
|
|
import AnimeNotifier from "../AnimeNotifier"
|
|
|
|
import { requestIdleCallback } from "../Utils"
|
2017-10-17 09:27:15 +00:00
|
|
|
|
|
|
|
// Load
|
|
|
|
export function load(arn: AnimeNotifier, element: HTMLElement) {
|
2019-04-22 06:05:16 +00:00
|
|
|
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
|
|
|
|
|
|
|
|
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-04-22 06:05:16 +00:00
|
|
|
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2017-10-17 09:27:15 +00:00
|
|
|
}
|