Skip to content

Commit

Permalink
Merge pull request #216 from cj12312021/patch-1
Browse files Browse the repository at this point in the history
Fixes some broken services from in stashUserscriptLibrary
  • Loading branch information
Maista6969 authored Jan 12, 2024
2 parents 8b3a9c2 + 71c96b0 commit 27e2fac
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions plugins/stashUserscriptLibrary/stashUserscriptLibrary.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 27e2fac

Please sign in to comment.