From d5e1ce4e3a86f0bb41839eca9c55d5f7ce6b0c63 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 19 Jul 2017 06:55:21 +0200 Subject: [PATCH] Improved caching --- scripts/AnimeNotifier.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 75df0498..d4082869 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -16,7 +16,7 @@ export class AnimeNotifier { statusMessage: StatusMessage visibilityObserver: IntersectionObserver pushManager: PushManager - lastRequestURL: string + mainPageLoaded: boolean imageFound: MutationQueue imageNotFound: MutationQueue @@ -199,14 +199,16 @@ export class AnimeNotifier { url: "" } - if(this.lastRequestURL) { - message.url = this.lastRequestURL - } else if(this.app.lastRequest) { - message.url = this.app.lastRequest.responseURL + // If mainPageLoaded is set, it means every single request is now an AJAX request for the /_/ prefixed page + if(this.mainPageLoaded) { + message.url = window.location.origin + "/_" + window.location.pathname } else { + this.mainPageLoaded = true message.url = window.location.href } + console.log("Loaded", message.url) + navigator.serviceWorker.controller.postMessage(JSON.stringify(message)) } @@ -318,9 +320,8 @@ export class AnimeNotifier { headers.append("X-Reload", "true") let path = this.app.currentPath - this.lastRequestURL = location.origin + "/_" + path - return fetch(this.lastRequestURL, { + return fetch("/_" + path, { credentials: "same-origin", headers }) @@ -514,7 +515,6 @@ export class AnimeNotifier { } let path = "/_" + url - this.lastRequestURL = location.origin + "/_" + path let request = fetch(path, { credentials: "same-origin"