11import { UfsGlobal } from "./content-scripts/ufs_global.js" ;
22
3+ // NOTES: functions that end with _ are required access token
4+
35// Helpers
46export async function fetchGraphQl ( str , fb_dtsg ) {
5- var fb_dtsg = "fb_dtsg=" + encodeURIComponent ( fb_dtsg ) ;
7+ fb_dtsg = "fb_dtsg=" + encodeURIComponent ( fb_dtsg ) ;
68 fb_dtsg += str . includes ( "variables" )
79 ? "&" + str
810 : "&q=" + encodeURIComponent ( str ) ;
@@ -46,11 +48,7 @@ export async function getFbdtsg() {
4648}
4749// User Data
4850export function getUserAvatarFromUid ( uid ) {
49- return (
50- "https://graph.facebook.com/" +
51- uid +
52- "/picture?height=500&access_token=6628568379%7Cc1e620fa708a1d5696fb991c1bde5662"
53- ) ;
51+ return `https://graph.facebook.com/${ uid } /picture?height=500&access_token=6628568379%7Cc1e620fa708a1d5696fb991c1bde5662` ;
5452}
5553export async function getYourUserId ( ) {
5654 let methods = [
@@ -108,7 +106,7 @@ export async function getUserInfoFromUid(uid) {
108106 alternateName : / " a l t e r n a t e _ n a m e " : " ( .* ?) " / . exec ( text ) ?. [ 1 ] ,
109107 } ;
110108}
111- export async function getUserInfo ( uid , access_token ) {
109+ export async function getUserInfo_ ( uid , access_token ) {
112110 let fields = [
113111 "birthday" ,
114112 "age_range" ,
@@ -125,7 +123,7 @@ export async function getUserInfo(uid, access_token) {
125123 "short_name" ,
126124 "picture" ,
127125 ] . join ( "," ) ;
128- var n = `https://graph.facebook.com/${ uid } /?fields=${ fields } &access_token=${ access_token } ` ;
126+ let n = `https://graph.facebook.com/${ uid } /?fields=${ fields } &access_token=${ access_token } ` ;
129127 const e = await fetch ( n ) ;
130128 let json = await e . json ( ) ;
131129 console . log ( json ) ;
@@ -141,10 +139,10 @@ export async function getUidFromUrl(url) {
141139 let methods = [
142140 ( ) => require ( "CometRouteStore" ) . getRoute ( url ) . rootView . props . userID ,
143141 async ( ) => {
144- var response = await fetch ( url ) ;
142+ let response = await fetch ( url ) ;
145143 if ( response . status == 200 ) {
146- var text = await response . text ( ) ;
147- let uid = / (?< = \ "u s e r I D \" \: \ ") ( .\d + ?) (? = \ ") / . exec ( text ) ;
144+ let text = await response . text ( ) ;
145+ let uid = / (?< = " u s e r I D " : " ) ( .\d + ?) (? = " ) / . exec ( text ) ;
148146 if ( uid ?. length ) {
149147 return uid [ 0 ] ;
150148 }
@@ -277,13 +275,13 @@ export async function getStoryInfo(bucketID, fb_dtsg) {
277275}
278276// Friend
279277export async function removeFriendConfirm ( friend_uid , uid , fb_dtsg ) {
280- var f = new FormData ( ) ;
281- f . append ( "uid" , friend_uid ) ,
282- f . append ( "unref" , "bd_friends_tab" ) ,
283- f . append ( "floc" , "friends_tab" ) ,
284- f . append ( "__user" , uid ) ,
285- f . append ( "__a" , 1 ) ,
286- f . append ( "fb_dtsg" , fb_dtsg ) ;
278+ let f = new FormData ( ) ;
279+ f . append ( "uid" , friend_uid ) ;
280+ f . append ( "unref" , "bd_friends_tab" ) ;
281+ f . append ( "floc" , "friends_tab" ) ;
282+ f . append ( "__user" , uid ) ;
283+ f . append ( "__a" , 1 ) ;
284+ f . append ( "fb_dtsg" , fb_dtsg ) ;
287285 await fetch (
288286 "https://www.facebook.com/ajax/ajax/profile/removefriendconfirm.php?dpr=1" ,
289287 {
@@ -293,21 +291,54 @@ export async function removeFriendConfirm(friend_uid, uid, fb_dtsg) {
293291 }
294292 ) ;
295293}
294+ export async function fetchAllFriends_ ( access_token , progressCallback ) {
295+ let friends = [ ] ;
296+ let total = 0 ;
297+ let limit = 25 ;
298+ let after = null ;
299+
300+ while ( true ) {
301+ try {
302+ const res = await fetch (
303+ `https://graph.facebook.com/v19.0/me?fields=friends` +
304+ `&access_token=${ access_token } &pretty=0&limit=${ limit } ` +
305+ ( after ? `&after=${ after } ` : "" )
306+ ) ;
307+ const json = await res . json ( ) ;
308+ const { data, paging, summary } = json . friends ;
309+ total = summary . total_count || total ;
310+ friends = friends . concat ( data ) ;
311+
312+ progressCallback ?. ( {
313+ data : friends ,
314+ loaded : friends . length ,
315+ total,
316+ } ) ;
317+
318+ if ( ! paging ?. cursors ?. after || paging . cursors . after === after ) break ;
319+ after = paging . cursors . after ;
320+ } catch ( e ) {
321+ console . error ( e ) ;
322+ break ;
323+ }
324+ }
325+ return friends ;
326+ }
296327export async function fetchAddedFriends ( uid , fb_dtsg , cursor ) {
297328 let variables = JSON . stringify ( {
298329 count : 8 ,
299330 cursor : cursor ?? null ,
300331 category_key : "FRIENDS" ,
301332 } ) ;
302333 const t = new URLSearchParams ( ) ;
303- t . append ( "__user" , uid ) ,
304- t . append ( "__a" , 1 ) ,
305- t . append ( "dpr" , 1 ) ,
306- t . append ( "fb_dtsg" , fb_dtsg ) ,
307- t . append ( "fb_api_caller_class" , "RelayModern" ) ,
308- t . append ( "fb_api_req_friendly_name" , "ActivityLogStoriesQuery" ) ,
309- t . append ( "doc_id" , "2761528123917382" ) ,
310- t . append ( "variables" , variables ) ;
334+ t . append ( "__user" , uid ) ;
335+ t . append ( "__a" , 1 ) ;
336+ t . append ( "dpr" , 1 ) ;
337+ t . append ( "fb_dtsg" , fb_dtsg ) ;
338+ t . append ( "fb_api_caller_class" , "RelayModern" ) ;
339+ t . append ( "fb_api_req_friendly_name" , "ActivityLogStoriesQuery" ) ;
340+ t . append ( "doc_id" , "2761528123917382" ) ;
341+ t . append ( "variables" , variables ) ;
311342
312343 let res = await fetch ( "https://www.facebook.com/api/graphql/" , {
313344 method : "POST" ,
@@ -394,14 +425,14 @@ export async function messagesCount(fb_dtsg) {
394425}
395426// Page
396427export async function unlikePage ( pageId , uid , fb_dtsg ) {
397- var f = new FormData ( ) ;
398- f . append ( "fbpage_id" , pageId ) ,
399- f . append ( "add" , false ) ,
400- f . append ( "reload" , false ) ,
401- f . append ( "fan_origin" , "page_timeline" ) ,
402- f . append ( "__user" , uid ) ,
403- f . append ( "__a" , 1 ) ,
404- f . append ( "fb_dtsg" , fb_dtsg ) ;
428+ let f = new FormData ( ) ;
429+ f . append ( "fbpage_id" , pageId ) ;
430+ f . append ( "add" , false ) ;
431+ f . append ( "reload" , false ) ;
432+ f . append ( "fan_origin" , "page_timeline" ) ;
433+ f . append ( "__user" , uid ) ;
434+ f . append ( "__a" , 1 ) ;
435+ f . append ( "fb_dtsg" , fb_dtsg ) ;
405436 await fetch ( "https://www.facebook.com/ajax/pages/fan_status.php?dpr=1" , {
406437 method : "POST" ,
407438 credentials : "include" ,
@@ -487,11 +518,11 @@ export async function searchAllPageForOther(
487518}
488519// Group
489520export async function leaveGroup ( groupId , uid , fb_dtsg ) {
490- var f = new FormData ( ) ;
491- f . append ( "fb_dtsg" , fb_dtsg ) ,
492- f . append ( "confirmed" , 1 ) ,
493- f . append ( "__user" , uid ) ,
494- f . append ( "__a" , 1 ) ;
521+ let f = new FormData ( ) ;
522+ f . append ( "fb_dtsg" , fb_dtsg ) ;
523+ f . append ( "confirmed" , 1 ) ;
524+ f . append ( "__user" , uid ) ;
525+ f . append ( "__a" , 1 ) ;
495526 await fetch (
496527 "https://www.facebook.com/ajax/groups/membership/leave.php?group_id=" +
497528 groupId +
0 commit comments