From 71c96b0428350fe61145bb09ec714273f04ca4f4 Mon Sep 17 00:00:00 2001 From: CJ <72030708+cj12312021@users.noreply.github.com> Date: Tue, 9 Jan 2024 17:31:13 -0600 Subject: [PATCH] Fixes some broken services from this library --- .../stashUserscriptLibrary.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugins/stashUserscriptLibrary/stashUserscriptLibrary.js b/plugins/stashUserscriptLibrary/stashUserscriptLibrary.js index 9cac420..7670e3b 100644 --- a/plugins/stashUserscriptLibrary/stashUserscriptLibrary.js +++ b/plugins/stashUserscriptLibrary/stashUserscriptLibrary.js @@ -1,5 +1,28 @@ const stashListener = new EventTarget(); +const { + fetch: originalFetch +} = window; + +window.fetch = async (...args) => { + let [resource, config] = args; + // request interceptor here + const response = await originalFetch(resource, config); + // response interceptor here + const contentType = response.headers.get("content-type"); + if (contentType && contentType.indexOf("application/json") !== -1 && resource.endsWith('/graphql')) { + try { + const data = await response.clone().json(); + stashListener.dispatchEvent(new CustomEvent('response', { + 'detail': data + })); + } catch (e) { + + } + } + return response; +}; + class Logger { constructor(enabled) { this.enabled = enabled;