@@ -132,14 +132,30 @@ const UsefulScriptGlobalPageContext = {
132132 } ,
133133 } ,
134134 Facebook : {
135+ async fetchGraphQl ( str , token ) {
136+ var fb_dtsg = "fb_dtsg=" + encodeURIComponent ( token ) ;
137+ fb_dtsg += str . includes ( "variables" )
138+ ? "&" + str
139+ : "&q=" + encodeURIComponent ( str ) ;
140+
141+ let res = await fetch ( "https://www.facebook.com/api/graphql/" , {
142+ body : fb_dtsg ,
143+ method : "POST" ,
144+ headers : { "Content-Type" : "application/x-www-form-urlencoded" } ,
145+ credentials : "include" ,
146+ } ) ;
147+
148+ let json = await res . json ( ) ;
149+ return json ;
150+ } ,
135151 getUserAvatarFromUid ( uid ) {
136152 return (
137153 "https://graph.facebook.com/" +
138154 uid +
139155 "/picture?height=500&access_token=6628568379%7Cc1e620fa708a1d5696fb991c1bde5662"
140156 ) ;
141157 } ,
142- getUserProfileDataFromUid : async ( uid ) => {
158+ async getUserInfoFromUid ( uid ) {
143159 const variables = {
144160 userID : uid ,
145161 shouldDeferProfilePic : false ,
@@ -173,10 +189,19 @@ const UsefulScriptGlobalPageContext = {
173189 alternateName : / " a l t e r n a t e _ n a m e " : " ( .* ?) " / . exec ( text ) ?. [ 1 ] ,
174190 } ;
175191 } ,
192+ async getUserInfo ( uid , access_token ) {
193+ var n =
194+ "https://graph.facebook.com/" +
195+ encodeURIComponent ( uid ) +
196+ "/?fields=name,picture&access_token=" +
197+ access_token ;
198+ const e = await fetch ( n ) ;
199+ return await e . json ( ) ;
200+ } ,
176201 decodeArrId ( arrId ) {
177202 return arrId [ 0 ] * 4294967296 + arrId [ 1 ] ;
178203 } ,
179- getUidFromUrl : async ( url ) => {
204+ async getUidFromUrl ( url ) {
180205 let methods = [
181206 ( ) => require ( "CometRouteStore" ) . getRoute ( url ) . rootView . props . userID ,
182207 async ( ) => {
@@ -245,9 +270,8 @@ const UsefulScriptGlobalPageContext = {
245270 }
246271 return null ;
247272 } ,
248-
249273 // Source: https://pastebin.com/CNvUxpfc
250- getStoryInfo : async ( bucketID , fb_dtsg ) => {
274+ async getStoryInfo ( bucketID , fb_dtsg ) {
251275 let body = new URLSearchParams ( ) ;
252276 body . append ( "__a" , 1 ) ;
253277 body . append ( "fb_dtsg" , fb_dtsg ) ;
@@ -360,6 +384,62 @@ const UsefulScriptGlobalPageContext = {
360384 // xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
361385 // xhr.send(body);
362386 } ,
387+ async unlikePage ( pageId , user , fb_dtsg ) {
388+ var f = new FormData ( ) ;
389+ f . append ( "fbpage_id" , pageId ) ,
390+ f . append ( "add" , false ) ,
391+ f . append ( "reload" , false ) ,
392+ f . append ( "fan_origin" , "page_timeline" ) ,
393+ f . append ( "__user" , user ) ,
394+ f . append ( "__a" , 1 ) ,
395+ f . append ( "fb_dtsg" , fb_dtsg ) ;
396+ await fetch ( "https://www.facebook.com/ajax/pages/fan_status.php?dpr=1" , {
397+ method : "POST" ,
398+ credentials : "include" ,
399+ body : f ,
400+ } ) ;
401+ } ,
402+ async leaveGroup ( groupId , user , fb_dtsg ) {
403+ var f = new FormData ( ) ;
404+ f . append ( "fb_dtsg" , fb_dtsg ) ,
405+ f . append ( "confirmed" , 1 ) ,
406+ f . append ( "__user" , user ) ,
407+ f . append ( "__a" , 1 ) ;
408+ await fetch (
409+ "https://www.facebook.com/ajax/groups/membership/leave.php?group_id=" +
410+ groupId +
411+ "&dpr=1" ,
412+ {
413+ method : "POST" ,
414+ credentials : "include" ,
415+ body : f ,
416+ }
417+ ) ;
418+ } ,
419+ async removeFriendConfirm ( friend_uid , user , fb_dtsg ) {
420+ var f = new FormData ( ) ;
421+ f . append ( "uid" , friend_uid ) ,
422+ f . append ( "unref" , "bd_friends_tab" ) ,
423+ f . append ( "floc" , "friends_tab" ) ,
424+ f . append ( "__user" , user ) ,
425+ f . append ( "__a" , 1 ) ,
426+ f . append ( "fb_dtsg" , fb_dtsg ) ;
427+ await fetch (
428+ "https://www.facebook.com/ajax/ajax/profile/removefriendconfirm.php?dpr=1" ,
429+ {
430+ method : "POST" ,
431+ credentials : "include" ,
432+ body : f ,
433+ }
434+ ) ;
435+ } ,
436+ async messagesCount ( token ) {
437+ let res = await UsefulScriptGlobalPageContext . Facebook . fetchGraphQl (
438+ "viewer(){message_threads{count,nodes{customization_info{emoji,outgoing_bubble_color,participant_customizations{participant_id,nickname}},all_participants{nodes{messaging_actor{name,id,profile_picture}}},thread_type,name,messages_count,image,id}}}" ,
439+ token
440+ ) ;
441+ return await res . json ( ) ;
442+ } ,
363443 } ,
364444} ;
365445window . UsefulScriptGlobalPageContext = UsefulScriptGlobalPageContext ;
0 commit comments