|
| 1 | +import { showLoading } from "./helpers/utils.js"; |
| 2 | + |
| 3 | +export default { |
| 4 | + icon: "", |
| 5 | + name: { |
| 6 | + en: "Test", |
| 7 | + vi: "Test", |
| 8 | + }, |
| 9 | + description: { |
| 10 | + en: "", |
| 11 | + vi: "", |
| 12 | + }, |
| 13 | + |
| 14 | + onClickExtension: async () => { |
| 15 | + async function searchGroupForOther(other_uid, cursor, uid, dtsg) { |
| 16 | + let variables = JSON.stringify({ |
| 17 | + count: 8, |
| 18 | + cursor: cursor ?? null, |
| 19 | + id: btoa(`app_collection:${other_uid}:2361831622:66`), |
| 20 | + }); |
| 21 | + |
| 22 | + let f = new URLSearchParams(); |
| 23 | + f.append("__user", uid); |
| 24 | + f.append("__a", 1); |
| 25 | + f.append("dpr", 1); |
| 26 | + f.append("fb_dtsg", dtsg); |
| 27 | + f.append("fb_api_caller_class", "RelayModern"); |
| 28 | + f.append( |
| 29 | + "fb_api_req_friendly_name", |
| 30 | + "ProfileCometAppCollectionGridRendererPaginationQuery" |
| 31 | + ); |
| 32 | + f.append("variables", variables); |
| 33 | + f.append("doc_id", 5244211935648733); |
| 34 | + |
| 35 | + try { |
| 36 | + let res = await fetch("https://www.facebook.com/api/graphql/", { |
| 37 | + method: "POST", |
| 38 | + body: f, |
| 39 | + }); |
| 40 | + |
| 41 | + let json = await res.json(); |
| 42 | + let { pageItems } = json.data.node; |
| 43 | + return { |
| 44 | + nextCursor: pageItems.page_info.end_cursor, |
| 45 | + groups: pageItems.edges.map((e) => ({ |
| 46 | + id: e.node.node?.id || btoa(e.node.id).split(":").at(-1), |
| 47 | + title: e.node.title.text, |
| 48 | + subTitle: e.node.subtitle_text.text, |
| 49 | + url: e.node.url, |
| 50 | + visibility: e.node.node.visibility, |
| 51 | + image: e.node.image.uri, |
| 52 | + membersCount: Number( |
| 53 | + ( |
| 54 | + e.node.node.forum_member_profiles.formatted_count_text || |
| 55 | + e.node.node.group_member_profiles.formatted_count_text |
| 56 | + ).match(/\d+/)?.[0] ?? 1 |
| 57 | + ), |
| 58 | + cursor: e.cursor, |
| 59 | + })), |
| 60 | + }; |
| 61 | + } catch (e) { |
| 62 | + console.log("ERROR fetch page", e); |
| 63 | + return { |
| 64 | + nextCursor: null, |
| 65 | + groups: [], |
| 66 | + }; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + async function searchAllGroupForOther( |
| 71 | + other_uid, |
| 72 | + uid, |
| 73 | + dtsg, |
| 74 | + pageFetchedCallback |
| 75 | + ) { |
| 76 | + let cursor = ""; |
| 77 | + let allGroups = []; |
| 78 | + while (true) { |
| 79 | + let { nextCursor, groups } = await searchGroupForOther( |
| 80 | + other_uid, |
| 81 | + cursor, |
| 82 | + uid, |
| 83 | + dtsg |
| 84 | + ); |
| 85 | + if (!nextCursor) { |
| 86 | + break; |
| 87 | + } |
| 88 | + cursor = nextCursor; |
| 89 | + allGroups = allGroups.concat(groups); |
| 90 | + await pageFetchedCallback?.(groups, allGroups); |
| 91 | + } |
| 92 | + return allGroups; |
| 93 | + } |
| 94 | + |
| 95 | + let url = prompt("Nhập link facebook bạn bè: "); |
| 96 | + if (url == null) return; |
| 97 | + |
| 98 | + let { setLoadingText, closeLoading } = showLoading("Đang chuẩn bị..."); |
| 99 | + try { |
| 100 | + let { getUidFromUrl, getYourUserId, getFbdtsg } = |
| 101 | + UsefulScriptGlobalPageContext.Facebook; |
| 102 | + |
| 103 | + setLoadingText("Đang lấy uid, token..."); |
| 104 | + let other_uid = await getUidFromUrl(url); |
| 105 | + let uid = await getYourUserId(); |
| 106 | + let dtsg = await getFbdtsg(); |
| 107 | + |
| 108 | + setLoadingText("Đang tải thông tin group..."); |
| 109 | + let allGroups = await searchAllGroupForOther( |
| 110 | + other_uid, |
| 111 | + uid, |
| 112 | + dtsg, |
| 113 | + (groups, all) => { |
| 114 | + setLoadingText( |
| 115 | + "Đang tải thông tin group...\nTải được " + all.length + " group." |
| 116 | + ); |
| 117 | + } |
| 118 | + ); |
| 119 | + console.log(allGroups); |
| 120 | + } catch (e) { |
| 121 | + alert("ERROR: " + e); |
| 122 | + } finally { |
| 123 | + closeLoading(); |
| 124 | + } |
| 125 | + }, |
| 126 | +}; |
0 commit comments