1
1
import { deepFindKeyInObject , getRedirectedUrl , sleep } from "./utils.js" ;
2
2
3
3
const CACHED = {
4
- uid : null ,
5
- fb_dtsg : null ,
4
+ fb_dtsg : { } ,
6
5
urlToId : { } ,
7
6
} ;
8
7
9
8
export async function getMyUid ( ) {
10
- if ( CACHED . uid ) return CACHED . uid ;
11
- const d = await chrome . cookies . get ( {
12
- url : "https://www.facebook.com" ,
13
- name : "c_user" ,
14
- } ) ;
15
- CACHED . uid = d ?. value ;
16
- return CACHED . uid ;
9
+ for ( let i of [ "i_user" , "c_user" ] ) {
10
+ const d = await chrome . cookies . get ( {
11
+ url : "https://www.facebook.com" ,
12
+ name : i ,
13
+ } ) ;
14
+ if ( d ?. value ) return d ?. value ;
15
+ }
16
+ return null ;
17
17
}
18
18
19
19
export async function fetchGraphQl ( params , url ) {
@@ -76,7 +76,9 @@ export function wrapGraphQlParams(params = {}) {
76
76
}
77
77
78
78
export async function getFbDtsg ( ) {
79
- if ( CACHED . fb_dtsg ) return CACHED . fb_dtsg ;
79
+ const uid = await getMyUid ( ) ;
80
+
81
+ if ( CACHED . fb_dtsg [ uid ] ) return CACHED . fb_dtsg [ uid ] ;
80
82
let res = await fetch ( "https://mbasic.facebook.com/photos/upload/" ) ;
81
83
let text = await res . text ( ) ;
82
84
let dtsg = RegExp ( / n a m e = " f b _ d t s g " v a l u e = " ( .* ?) " / ) . exec ( text ) ?. [ 1 ] ;
@@ -91,8 +93,8 @@ export async function getFbDtsg() {
91
93
RegExp ( / " d t s g " : { " t o k e n " : " ( [ ^ " ] + ) " / ) . exec ( text ) ?. [ 1 ] ||
92
94
RegExp ( / " n a m e " : " f b _ d t s g " , " v a l u e " : " ( [ ^ " ] + ) / ) . exec ( text ) ?. [ 1 ] ;
93
95
}
94
- CACHED . fb_dtsg = dtsg || null ;
95
- return CACHED . fb_dtsg ;
96
+ CACHED . fb_dtsg [ uid ] = dtsg || null ;
97
+ return CACHED . fb_dtsg [ uid ] ;
96
98
}
97
99
98
100
export function findDataObject ( object ) {
@@ -236,6 +238,7 @@ export async function getEntityAbout(entityID, context = "DEFAULT") {
236
238
doc_id : "7257793420991802" ,
237
239
} ) ;
238
240
const json = JSON . parse ( res ) ;
241
+ console . log ( json ) ;
239
242
const node = json . data . node ;
240
243
if ( ! node ) throw new Error ( "Wrong ID / Entity not found" ) ;
241
244
const typeText = node . __typename . toLowerCase ( ) ;
@@ -289,7 +292,21 @@ export async function sharePostToGroup({
289
292
if ( ! groupId ) {
290
293
throw new Error ( "Không lấy được group id" ) ;
291
294
}
292
- console . log ( "group" , groupId , "postOwner" , postOwner , "post" , postId ) ;
295
+ const myUid = await getMyUid ( ) ;
296
+ const me = await getEntityAbout ( myUid ) ;
297
+ if ( ! me ) {
298
+ throw new Error ( "Không lấy được thông tin nick của bạn" ) ;
299
+ }
300
+ console . log (
301
+ "group" ,
302
+ groupId ,
303
+ "postOwner" ,
304
+ postOwner ,
305
+ "post" ,
306
+ postId ,
307
+ "me" ,
308
+ me
309
+ ) ;
293
310
294
311
const res = await fetchGraphQl ( {
295
312
fb_api_req_friendly_name : "ComposerStoryCreateMutation" ,
@@ -307,10 +324,8 @@ export async function sharePostToGroup({
307
324
attachments : [
308
325
{
309
326
link : {
310
- // group -> group: 37
311
- // page -> group: 22
312
327
share_scrape_data : JSON . stringify ( {
313
- share_type : postOwner . type === TargetType . Group ? 37 : 22 ,
328
+ share_type : me . type === TargetType . Page ? 37 : 22 ,
314
329
share_params : [ postId ] ,
315
330
} ) ,
316
331
} ,
@@ -357,7 +372,7 @@ export async function sharePostToGroup({
357
372
__relay_internal__pv__StoriesArmadilloReplyEnabledrelayprovider : true ,
358
373
__relay_internal__pv__EventCometCardImage_prefetchEventImagerelayprovider : false ,
359
374
} ,
360
- doc_id : "8148691861851794 " ,
375
+ doc_id : "8358507460852422 " ,
361
376
} ) ;
362
377
const json = JSON . parse ( res ?. split ?. ( "\n" ) ?. [ 0 ] ) ;
363
378
console . log ( json ) ;
0 commit comments