@@ -607,6 +607,26 @@ async function onDocumentEnd() {
607
607
document . body . prepend ( container ) ;
608
608
609
609
// #endregion
610
+
611
+ // #region auto get fb info of selected text on press A
612
+
613
+ document . addEventListener ( "keydown" , ( event ) => {
614
+ const selectedText = UfsGlobal . DOM . getSelectionText ( ) ;
615
+ if ( selectedText ) {
616
+ if ( event . key === "a" ) {
617
+ getEntityAbout ( selectedText )
618
+ . then ( ( data ) =>
619
+ alert ( data . type + ":\n" + data . name + "\n\n" + data . url )
620
+ )
621
+ . catch ( ( e ) => alert ( "ERROR: " + e . message ) ) ;
622
+ }
623
+ if ( event . key === "d" ) {
624
+ window . open ( "https://fb.com/" + selectedText , "_blank" ) ;
625
+ }
626
+ }
627
+ } ) ;
628
+
629
+ // #endregion
610
630
}
611
631
612
632
function getCurrentLogDate ( ) {
@@ -677,24 +697,22 @@ async function initCache() {
677
697
async function getFbProfile ( uid , force = false ) {
678
698
if ( CACHED . fbProfile . has ( uid ) && ! force ) return CACHED . fbProfile . get ( uid ) ;
679
699
680
- const variables = {
681
- userID : uid ,
682
- shouldDeferProfilePic : false ,
683
- useVNextHeader : false ,
684
- scale : 1.5 ,
685
- } ;
686
- let f = new URLSearchParams ( ) ;
687
- f . append ( "fb_dtsg" , CACHED . fb_dtsg ) ;
688
- f . append ( "fb_api_req_friendly_name" , "ProfileCometHeaderQuery" ) ;
689
- f . append ( "variables" , JSON . stringify ( variables ) ) ;
690
- f . append ( "doc_id" , "4159355184147969" ) ;
691
-
692
700
let res = await UfsGlobal . Extension . runInBackground ( "fetch" , [
693
701
"https://www.facebook.com/api/graphql/" ,
694
702
{
695
703
method : "POST" ,
696
704
headers : { "content-type" : "application/x-www-form-urlencoded" } ,
697
- body : f . toString ( ) ,
705
+ body : new URLSearchParams ( {
706
+ fb_api_req_friendly_name : "ProfileCometHeaderQuery" ,
707
+ fb_dtsg : CACHED . fb_dtsg ,
708
+ variables : JSON . stringify ( {
709
+ userID : uid ,
710
+ shouldDeferProfilePic : false ,
711
+ useVNextHeader : false ,
712
+ scale : 1.5 ,
713
+ } ) ,
714
+ doc_id : "4159355184147969" ,
715
+ } ) . toString ( ) ,
698
716
} ,
699
717
] ) ;
700
718
@@ -725,6 +743,58 @@ async function getFbProfile(uid, force = false) {
725
743
return info ;
726
744
}
727
745
746
+ export const TargetType = {
747
+ User : "user" ,
748
+ Page : "page" ,
749
+ Group : "group" ,
750
+ IGUser : "ig_user" ,
751
+ } ;
752
+
753
+ export async function getEntityAbout ( entityID , context = "DEFAULT" ) {
754
+ let res = await UfsGlobal . Extension . runInBackground ( "fetch" , [
755
+ "https://www.facebook.com/api/graphql/" ,
756
+ {
757
+ method : "POST" ,
758
+ headers : { "content-type" : "application/x-www-form-urlencoded" } ,
759
+ body : new URLSearchParams ( {
760
+ fb_api_req_friendly_name : "CometHovercardQueryRendererQuery" ,
761
+ fb_dtsg : CACHED . fb_dtsg ,
762
+ variables : JSON . stringify ( {
763
+ actionBarRenderLocation : "WWW_COMET_HOVERCARD" ,
764
+ context : context ,
765
+ entityID : entityID ,
766
+ includeTdaInfo : true ,
767
+ scale : 1 ,
768
+ } ) ,
769
+ doc_id : "7257793420991802" ,
770
+ } ) . toString ( ) ,
771
+ } ,
772
+ ] ) ;
773
+ console . log ( res ) ;
774
+ const text = await res . body ;
775
+ const json = JSON . parse ( text ) ;
776
+ const node = json . data . node ;
777
+ if ( ! node ) throw new Error ( "Wrong ID / Entity not found" ) ;
778
+ const typeText = node . __typename . toLowerCase ( ) ;
779
+ if ( ! Object . values ( TargetType ) . includes ( typeText ) )
780
+ throw new Error ( "Not supported type: " + typeText ) ;
781
+ const card = node . comet_hovercard_renderer [ typeText ] ;
782
+ const type =
783
+ typeText === "user"
784
+ ? card . profile_plus_transition_path ?. startsWith ( "PAGE" )
785
+ ? TargetType . Page
786
+ : TargetType . User
787
+ : TargetType . Group ;
788
+ return {
789
+ type,
790
+ id : node . id || card . id ,
791
+ name : card . name ,
792
+ avatar : card . profile_picture . uri ,
793
+ url : card . profile_url || card . url ,
794
+ raw : json ,
795
+ } ;
796
+ }
797
+
728
798
// log example: 5/31/2024, 9:13:41 AM: OPEN-TAB-unlock (1.67-1717121281787) -> 43
729
799
function extractUid ( log ) {
730
800
return / - ( \d + ) \) / . exec ( log ) ?. [ 1 ] || "?" ;
0 commit comments