Async JavaScript load
This commit is contained in:
parent
c7f482c525
commit
e63be2c43a
@ -54,7 +54,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
|
|||||||
ExtensionNavigation(user)
|
ExtensionNavigation(user)
|
||||||
if user != nil
|
if user != nil
|
||||||
#user(data-id=user.ID, data-pro=user.IsPro(), data-theme=user.Settings().Theme)
|
#user(data-id=user.ID, data-pro=user.IsPro(), data-theme=user.Settings().Theme)
|
||||||
script(src="/scripts")
|
script(src="/scripts", async="async")
|
||||||
script(type="application/ld+json")!= organization
|
script(type="application/ld+json")!= organization
|
||||||
|
|
||||||
component Content(content string)
|
component Content(content string)
|
||||||
|
@ -3,7 +3,12 @@ import AnimeNotifier from "../AnimeNotifier"
|
|||||||
// Chrome extension installation
|
// Chrome extension installation
|
||||||
export function installExtension(arn: AnimeNotifier, button: HTMLElement) {
|
export function installExtension(arn: AnimeNotifier, button: HTMLElement) {
|
||||||
let browser: any = window["chrome"]
|
let browser: any = window["chrome"]
|
||||||
|
|
||||||
|
if(browser && browser.webstore) {
|
||||||
browser.webstore.install()
|
browser.webstore.install()
|
||||||
|
} else {
|
||||||
|
window.open("https://chrome.google.com/webstore/detail/anime-notifier/hajchfikckiofgilinkpifobdbiajfch", "_blank")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Desktop app installation
|
// Desktop app installation
|
||||||
|
@ -83,9 +83,13 @@ export default class AnimeNotifier {
|
|||||||
// Event listeners
|
// Event listeners
|
||||||
document.addEventListener("readystatechange", this.onReadyStateChange.bind(this))
|
document.addEventListener("readystatechange", this.onReadyStateChange.bind(this))
|
||||||
document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this))
|
document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this))
|
||||||
document.addEventListener("keydown", this.onKeyDown.bind(this), false)
|
|
||||||
window.addEventListener("popstate", this.onPopState.bind(this))
|
// If we finished loading the DOM (either "interactive" or "complete" state),
|
||||||
window.addEventListener("error", this.onError.bind(this))
|
// immediately trigger the event listener functions.
|
||||||
|
if(document.readyState !== "loading") {
|
||||||
|
this.app.emit("DOMContentLoaded")
|
||||||
|
this.run()
|
||||||
|
}
|
||||||
|
|
||||||
// Idle
|
// Idle
|
||||||
requestIdleCallback(this.onIdle.bind(this))
|
requestIdleCallback(this.onIdle.bind(this))
|
||||||
@ -176,6 +180,11 @@ export default class AnimeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onIdle() {
|
async onIdle() {
|
||||||
|
// Register event listeners
|
||||||
|
document.addEventListener("keydown", this.onKeyDown.bind(this), false)
|
||||||
|
window.addEventListener("popstate", this.onPopState.bind(this))
|
||||||
|
window.addEventListener("error", this.onError.bind(this))
|
||||||
|
|
||||||
// Service worker
|
// Service worker
|
||||||
this.serviceWorkerManager = new ServiceWorkerManager(this, "/service-worker")
|
this.serviceWorkerManager = new ServiceWorkerManager(this, "/service-worker")
|
||||||
this.serviceWorkerManager.register()
|
this.serviceWorkerManager.register()
|
||||||
|
@ -26,12 +26,14 @@ export default class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
onContentLoaded() {
|
||||||
let links = document.getElementsByTagName("a")
|
let links = document.getElementsByTagName("a")
|
||||||
|
|
||||||
this.markActiveLinks(links)
|
this.markActiveLinks(links)
|
||||||
this.ajaxify(links)
|
this.ajaxify(links)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url: string): Promise<string> {
|
get(url: string): Promise<string> {
|
||||||
|
Loading…
Reference in New Issue
Block a user