Skip to content

Commit 0d6095f

Browse files
committed
ajax hook + test
1 parent 8ca4401 commit 0d6095f

File tree

7 files changed

+740
-118
lines changed

7 files changed

+740
-118
lines changed

scripts/_test.js

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
import { UfsGlobal } from "./content-scripts/ufs_global.js";
2-
import {
3-
hookFetch,
4-
hookXHR,
5-
CANCEL_FETCH,
6-
CANCEL_XHR,
7-
cancelKey,
8-
} from "./libs/ajax-hook/index.js";
92

103
export default {
114
icon: "",
@@ -262,23 +255,6 @@ export default {
262255
},
263256

264257
pageScript: {
265-
onDocumentStart: () => {
266-
// hookFetch({
267-
// onBefore: (url, options) => {
268-
// console.log("onBefore", url, options);
269-
// },
270-
// });
271-
const unregister = hookXHR({
272-
onBefore: (params) => {
273-
if (params.url.includes("graphql")) console.log("before", params);
274-
},
275-
onAfter: (params, response) => {
276-
if (params.url.includes("graphql"))
277-
console.log("-> after", params, JSON.parse(response));
278-
},
279-
});
280-
},
281-
282258
// download album
283259
_onClick: async () => {
284260
(async () => {
@@ -717,52 +693,3 @@ export default {
717693
},
718694
},
719695
};
720-
721-
const backup = () => {
722-
(() => {
723-
// modify window.fetch
724-
const originalFetch = fetch;
725-
fetch = function (...args) {
726-
console.log("fetch", ...args);
727-
return originalFetch(...args).then(async (res) => {
728-
try {
729-
console.log("res ne", res);
730-
let clone = res.clone();
731-
let json = await clone.json();
732-
console.log("json", json);
733-
734-
json = {
735-
success: true,
736-
data: {},
737-
};
738-
console.log("modifiedJson", json);
739-
740-
let modifiedResponse = new Response(JSON.stringify(json));
741-
[
742-
"headers",
743-
"ok",
744-
"redirected",
745-
"status",
746-
"statusText",
747-
"type",
748-
"url",
749-
].forEach((key) => {
750-
modifiedResponse[key] = res[key];
751-
});
752-
753-
console.log("modifiedResponse", modifiedResponse);
754-
return modifiedResponse;
755-
} catch (e) {
756-
console.log("error", e);
757-
return res;
758-
}
759-
});
760-
};
761-
})();
762-
763-
(() => {
764-
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
765-
console.log("onMessage", request, sender, sendResponse);
766-
});
767-
})();
768-
};

0 commit comments

Comments
 (0)