@@ -3472,36 +3472,111 @@ const API = {
3472
3472
} ) ;
3473
3473
} ,
3474
3474
getLikers : ( id , cursor , count = 10 ) => {
3475
- return new Promise ( async ( resolve , reject ) => {
3476
- let activity = await fetch ( `https://api.x.com/1.1/statuses/${ id } /activity/summary.json?stringify_ids=1&cards_platform=Web-13&include_entities=1&include_user_entities=1&include_cards=1&send_error_codes=1&tweet_mode=extended&include_ext_alt_text=true&include_reply_count=true` , {
3477
- headers : {
3478
- "authorization" : "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA" ,
3479
- "x-csrf-token" : OLDTWITTER_CONFIG . csrf ,
3480
- "x-twitter-auth-type" : "OAuth2Session" ,
3481
- "content-type" : "application/json"
3482
- } ,
3483
- credentials : "include"
3484
- } ) . then ( i => i . json ( ) ) ;
3485
- if ( activity . errors && activity . errors [ 0 ] ) {
3486
- return resolve ( { list : [ ] , cursor : undefined } ) ;
3487
- }
3488
- if ( activity . favoriters . length === 0 ) {
3489
- return resolve ( { list : [ ] , cursor : undefined } ) ;
3490
- }
3491
- let list = activity . favoriters . slice ( 0 , count === 10 ? 10 : 100 ) ;
3492
- let lookup = await fetch ( `https://api.x.com/1.1/users/lookup.json?user_id=${ list . join ( ',' ) } &include_entities=1&include_cards=1&send_error_codes=1&tweet_mode=extended&include_ext_alt_text=true&include_reply_count=true` , {
3493
- headers : {
3494
- "authorization" : "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA" ,
3495
- "x-csrf-token" : OLDTWITTER_CONFIG . csrf ,
3496
- "x-twitter-auth-type" : "OAuth2Session" ,
3497
- "content-type" : "application/json"
3498
- } ,
3499
- credentials : "include"
3500
- } ) . then ( i => i . json ( ) ) ;
3501
- if ( lookup . errors && lookup . errors [ 0 ] ) {
3502
- return resolve ( { list : [ ] , cursor : undefined } ) ;
3503
- }
3504
- resolve ( { list : lookup , cursor : undefined } ) ;
3475
+ return new Promise ( ( resolve , reject ) => {
3476
+ let obj = {
3477
+ "tweetId" : id ,
3478
+ "count" : count ,
3479
+ "includePromotedContent" : false ,
3480
+ "withSuperFollowsUserFields" : true ,
3481
+ "withDownvotePerspective" : false ,
3482
+ "withReactionsMetadata" : false ,
3483
+ "withReactionsPerspective" : false ,
3484
+ "withSuperFollowsTweetFields" : true ,
3485
+ "withClientEventToken" : false ,
3486
+ "withBirdwatchNotes" : false ,
3487
+ "withVoice" : true ,
3488
+ "withV2Timeline" : true
3489
+ } ;
3490
+ if ( cursor ) obj . cursor = cursor ;
3491
+ chrome . storage . local . get ( [ 'tweetLikers' ] , d => {
3492
+ if ( ! cursor ) cursor = '' ;
3493
+ if ( ! d . tweetLikers ) d . tweetLikers = { } ;
3494
+ if ( ! cursor ) {
3495
+ if ( d . tweetLikers [ id ] && Date . now ( ) - d . tweetLikers [ id ] . date < 60000 ) {
3496
+ debugLog ( 'tweet.getLikers' , 'cache' , d . tweetLikers [ id ] . data ) ;
3497
+ return resolve ( d . tweetLikers [ id ] . data ) ;
3498
+ }
3499
+ if ( loadingLikers [ id ] ) {
3500
+ return loadingLikers [ id ] . listeners . push ( [ resolve , reject ] ) ;
3501
+ } else {
3502
+ loadingLikers [ id ] = {
3503
+ listeners : [ ]
3504
+ } ;
3505
+ }
3506
+ }
3507
+ fetch ( `/i/api/graphql/RMoTahkos95Jcdw-UWlZog/Favoriters?variables=${ encodeURIComponent ( JSON . stringify ( obj ) ) } &features=${ encodeURIComponent ( JSON . stringify ( {
3508
+ "dont_mention_me_view_api_enabled" : true ,
3509
+ "interactive_text_enabled" : true ,
3510
+ "responsive_web_uc_gql_enabled" : false ,
3511
+ "vibe_tweet_context_enabled" : false ,
3512
+ "responsive_web_edit_tweet_api_enabled" : false ,
3513
+ "standardized_nudges_misinfo" : false ,
3514
+ "responsive_web_enhance_cards_enabled" : false
3515
+ } ) ) } `, {
3516
+ headers : {
3517
+ "authorization" : OLDTWITTER_CONFIG . public_token ,
3518
+ "x-csrf-token" : OLDTWITTER_CONFIG . csrf ,
3519
+ "x-twitter-auth-type" : "OAuth2Session" ,
3520
+ "content-type" : "application/json"
3521
+ } ,
3522
+ credentials : "include"
3523
+ } ) . then ( i => i . json ( ) ) . then ( data => {
3524
+ debugLog ( 'tweet.getLikers' , 'start' , { id, cursor, data } ) ;
3525
+ if ( data . errors && data . errors [ 0 ] . code === 32 ) {
3526
+ if ( ! cursor ) {
3527
+ loadingLikers [ id ] . listeners . forEach ( l => l [ 1 ] ( 'Not logged in' ) ) ;
3528
+ delete loadingLikers [ id ] ;
3529
+ }
3530
+ return reject ( "Not logged in" ) ;
3531
+ }
3532
+ if ( data . errors && data . errors [ 0 ] ) {
3533
+ if ( ! cursor ) {
3534
+ loadingLikers [ id ] . listeners . forEach ( l => l [ 1 ] ( data . errors [ 0 ] . message ) ) ;
3535
+ delete loadingLikers [ id ] ;
3536
+ }
3537
+ return reject ( data . errors [ 0 ] . message ) ;
3538
+ }
3539
+ let list = data . data . favoriters_timeline . timeline . instructions . find ( i => i . type === 'TimelineAddEntries' ) ;
3540
+ if ( ! list ) {
3541
+ if ( ! cursor ) {
3542
+ loadingLikers [ id ] . listeners . forEach ( l => l [ 0 ] ( { list : [ ] , cursor : undefined } ) ) ;
3543
+ delete loadingLikers [ id ] ;
3544
+ }
3545
+ debugLog ( 'tweet.getLikers' , 'end' , id , { list : [ ] , cursor : undefined , data } ) ;
3546
+ return resolve ( { list : [ ] , cursor : undefined } ) ;
3547
+ }
3548
+ list = list . entries ;
3549
+ let rdata = {
3550
+ list : list . filter ( e => e . entryId . startsWith ( 'user-' ) ) . map ( e => {
3551
+ if (
3552
+ ! e . content . itemContent . user_results . result ||
3553
+ e . content . itemContent . user_results . result . __typename === "UserUnavailable"
3554
+ ) return ;
3555
+ let user = e . content . itemContent . user_results . result ;
3556
+ user . legacy . id_str = user . rest_id ;
3557
+ return user . legacy ;
3558
+ } ) . filter ( u => u ) ,
3559
+ cursor : list . find ( e => e . entryId . startsWith ( 'cursor-bottom-' ) ) . content . value
3560
+ } ;
3561
+ debugLog ( 'tweet.getLikers' , 'end' , id , rdata ) ;
3562
+ resolve ( rdata ) ;
3563
+ if ( ! cursor ) {
3564
+ loadingLikers [ id ] . listeners . forEach ( l => l [ 0 ] ( rdata ) ) ;
3565
+ delete loadingLikers [ id ] ;
3566
+ d . tweetLikers [ id ] = {
3567
+ date : Date . now ( ) ,
3568
+ data : rdata
3569
+ } ;
3570
+ chrome . storage . local . set ( { tweetLikers : d . tweetLikers } , ( ) => { } ) ;
3571
+ }
3572
+ } ) . catch ( e => {
3573
+ if ( ! cursor ) {
3574
+ loadingLikers [ id ] . listeners . forEach ( l => l [ 1 ] ( e ) ) ;
3575
+ delete loadingLikers [ id ] ;
3576
+ }
3577
+ reject ( e ) ;
3578
+ } ) ;
3579
+ } ) ;
3505
3580
} ) ;
3506
3581
} ,
3507
3582
getRetweeters : ( id , cursor ) => {
0 commit comments