diff --git a/layout/layout.pixy b/layout/layout.pixy index 2a50c668..2804543a 100644 --- a/layout/layout.pixy +++ b/layout/layout.pixy @@ -54,7 +54,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG ExtensionNavigation(user) if user != nil #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 component Content(content string) diff --git a/scripts/Actions/Install.ts b/scripts/Actions/Install.ts index 629a536b..32acdcda 100644 --- a/scripts/Actions/Install.ts +++ b/scripts/Actions/Install.ts @@ -3,7 +3,12 @@ import AnimeNotifier from "../AnimeNotifier" // Chrome extension installation export function installExtension(arn: AnimeNotifier, button: HTMLElement) { let browser: any = window["chrome"] - browser.webstore.install() + + if(browser && browser.webstore) { + browser.webstore.install() + } else { + window.open("https://chrome.google.com/webstore/detail/anime-notifier/hajchfikckiofgilinkpifobdbiajfch", "_blank") + } } // Desktop app installation diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 353df1b2..aa4f694a 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -83,9 +83,13 @@ export default class AnimeNotifier { // Event listeners document.addEventListener("readystatechange", this.onReadyStateChange.bind(this)) document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this)) - document.addEventListener("keydown", this.onKeyDown.bind(this), false) - window.addEventListener("popstate", this.onPopState.bind(this)) - window.addEventListener("error", this.onError.bind(this)) + + // If we finished loading the DOM (either "interactive" or "complete" state), + // immediately trigger the event listener functions. + if(document.readyState !== "loading") { + this.app.emit("DOMContentLoaded") + this.run() + } // Idle requestIdleCallback(this.onIdle.bind(this)) @@ -176,6 +180,11 @@ export default class AnimeNotifier { } 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 this.serviceWorkerManager = new ServiceWorkerManager(this, "/service-worker") this.serviceWorkerManager.register() diff --git a/scripts/Application.ts b/scripts/Application.ts index 1cca8967..054f5c54 100644 --- a/scripts/Application.ts +++ b/scripts/Application.ts @@ -26,12 +26,14 @@ export default class Application { } init() { - document.addEventListener("DOMContentLoaded", () => { - let links = document.getElementsByTagName("a") + document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this)) + } - this.markActiveLinks(links) - this.ajaxify(links) - }) + onContentLoaded() { + let links = document.getElementsByTagName("a") + + this.markActiveLinks(links) + this.ajaxify(links) } get(url: string): Promise {