Skip to content

Commit 5b102cc

Browse files
committed
optimize fb-all-in-one - WIP
1 parent 4bdce9b commit 5b102cc

File tree

1 file changed

+7
-34
lines changed

1 file changed

+7
-34
lines changed

scripts/fb_allInOne.js

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { BADGES } from "./helpers/badge.js";
2-
import { getFbdtsg, getYourUserId } from "./fb_GLOBAL.js";
2+
import { runFunc } from "./helpers/utils.js";
33

44
const CACHED = {
55
uid: null,
66
fb_dtsg: null,
77
};
88

9+
const GLOBAL = {
10+
fetch: (url, options) => fetch(url, options || {}).then((res) => res.text()),
11+
};
12+
913
export default {
1014
icon: '<i class="fa-brands fa-square-facebook fa-2xl"></i>',
1115
name: {
@@ -29,42 +33,11 @@ export default {
2933
backgroundScript: {
3034
runtime: {
3135
onMessageExternal: async ({ request, sender, sendResponse }, context) => {
32-
if (request.action === "fb_allInOne_init") {
33-
init().then(sendResponse);
34-
return true;
35-
}
36-
37-
if (request.action === "request_graphql" && request.query) {
38-
(async () => {
39-
if (!CACHED.fb_dtsg) await init();
40-
41-
fetch(request.url || "https://www.facebook.com/api/graphql/", {
42-
body: request.query + "&fb_dtsg=" + CACHED.fb_dtsg,
43-
method: "POST",
44-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
45-
credentials: "include",
46-
})
47-
.then((res) => res.text())
48-
.then(sendResponse)
49-
.catch((e) => sendResponse({ error: e.message }));
50-
})();
51-
return true;
52-
}
53-
54-
if (request.action === "fetch") {
55-
fetch(request.url, request.options || {})
56-
.then((res) => res.text())
57-
.then(sendResponse)
58-
.catch((e) => sendResponse({ error: e.message }));
36+
if (request.action === "fb_allInOne_runFunc") {
37+
runFunc(request.fnPath, request.params, GLOBAL).then(sendResponse);
5938
return true;
6039
}
6140
},
6241
},
6342
},
6443
};
65-
66-
async function init() {
67-
CACHED.uid = await getYourUserId();
68-
CACHED.fb_dtsg = await getFbdtsg();
69-
return CACHED;
70-
}

0 commit comments

Comments
 (0)