Skip to content

Commit 805da07

Browse files
committed
fix
1 parent c2acade commit 805da07

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

scripts/fb_allInOne.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ export default {
3030
runtime: {
3131
onMessageExternal: async ({ request, sender, sendResponse }, context) => {
3232
if (request.action === "fb_allInOne_init") {
33-
(async () => {
34-
CACHED.uid = await getYourUserId();
35-
CACHED.fb_dtsg = await getFbdtsg();
36-
sendResponse(CACHED);
37-
})();
33+
init().then(sendResponse);
3834
return true;
3935
}
4036

4137
if (request.action === "request_graphql" && request.query) {
42-
fetch(request.url || "https://www.facebook.com/api/graphql/", {
43-
body: request.query + "&fb_dtsg=" + CACHED.fb_dtsg,
44-
method: "POST",
45-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
46-
credentials: "include",
47-
})
48-
.then((res) => res.text())
49-
.then(sendResponse)
50-
.catch((e) => sendResponse({ error: e.message }));
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+
})();
5151
return true;
5252
}
5353

@@ -62,3 +62,9 @@ export default {
6262
},
6363
},
6464
};
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)