@@ -176,6 +176,165 @@ const UsefulScriptGlobalPageContext = {
176176 decodeArrId ( arrId ) {
177177 return arrId [ 0 ] * 4294967296 + arrId [ 1 ] ;
178178 } ,
179+ getStoryBucketIdFromURL ( url ) {
180+ return url . match ( / s t o r i e s \/ ( \d + ) \/ / ) ?. [ 1 ] ;
181+ } ,
182+ getStoryId ( ) {
183+ const htmlStory = document . getElementsByClassName (
184+ "xh8yej3 x1n2onr6 xl56j7k x5yr21d x78zum5 x6s0dn4"
185+ ) ;
186+ return htmlStory [ htmlStory . length - 1 ] . getAttribute ( "data-id" ) ;
187+ } ,
188+ getFbdtsg ( ) {
189+ let methods = [
190+ ( ) => require ( "DTSGInitData" ) . token ,
191+ ( ) => {
192+ const regex = / " D T S G I n i t i a l D a t a " , \[ ] ,{ " t o k e n " : " ( .+ ?) " / gm;
193+ const resp = regex . exec ( document . documentElement . innerHTML ) ;
194+ return resp [ 1 ] ;
195+ } ,
196+ ( ) => require ( "DTSG_ASYNC" ) . getToken ( ) , // TODO: trace xem tại sao method này trả về cấu trúc khác 2 method trên
197+ ] ;
198+ for ( let m of methods ) {
199+ try {
200+ return m ( ) ;
201+ } catch ( e ) { }
202+ }
203+ alert ( "Cannot get your Fb_dtsg" ) ;
204+ } ,
205+ getUserId ( ) {
206+ let methods = [
207+ ( ) => require ( "CurrentUserInitialData" ) . USER_ID ,
208+ ( ) => require ( "RelayAPIConfigDefaults" ) . actorID ,
209+ ( ) => document . cookie . match ( / c _ u s e r = ( \d + ) / ) [ 1 ] ,
210+ ( ) => {
211+ const regex = / c _ u s e r = ( \d + ) ; / gm;
212+ const resp = regex . exec ( document . cookie ) ;
213+ return resp [ 1 ] ;
214+ } ,
215+ ] ;
216+ for ( let m of methods ) {
217+ try {
218+ return m ( ) ;
219+ } catch ( e ) { }
220+ }
221+ alert ( "Cannot get your UID" ) ;
222+ } ,
223+
224+ // Source: https://pastebin.com/CNvUxpfc
225+ getStoryInfo : async ( bucketID , fb_dtsg ) => {
226+ let body = new URLSearchParams ( ) ;
227+ body . append ( "__a" , 1 ) ;
228+ body . append ( "fb_dtsg" , fb_dtsg ) ;
229+ body . append (
230+ "variables" ,
231+ JSON . stringify ( {
232+ bucketID : bucketID ,
233+ initialLoad : false ,
234+ scale : 1 ,
235+ } )
236+ ) ;
237+ body . append ( "doc_id" , 2586853698032602 ) ;
238+
239+ let res = await fetch ( "https://www.facebook.com/api/graphql/" , {
240+ method : "POST" ,
241+ headers : { "Content-Type" : "application/x-www-form-urlencoded" } ,
242+ body : body ,
243+ credentials : "include" ,
244+ } ) ;
245+
246+ let json = await res . json ( ) ;
247+ console . log ( json ) ;
248+ let data = json ?. data ?. bucket ;
249+
250+ if ( ! data ) throw new Error ( "Không lấy được data" ) ;
251+ return {
252+ storyId : data . id ,
253+ author : {
254+ id : data . owner . id ,
255+ name : data . owner . name ,
256+ avatar : data . owner . profile_picture . uri ,
257+ avatarURL : data . owner . url ,
258+ } ,
259+ Objects : data . unified_stories . edges . map ( ( _ , i ) => {
260+ return {
261+ pictureBlurred :
262+ data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
263+ . blurredImage . uri ,
264+
265+ picturePreview :
266+ data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
267+ . previewImage . uri ,
268+
269+ totalReaction :
270+ data . unified_stories . edges [ i ] . node . story_card_info
271+ . feedback_summary . total_reaction_count ,
272+
273+ backgroundCss :
274+ data . unified_stories . edges [ i ] . node . story_default_background . color ,
275+
276+ backgroundCss3 :
277+ data . unified_stories . edges [ i ] . node . story_default_background
278+ . gradient . css ,
279+
280+ ...( data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
281+ . __typename == "Photo"
282+ ? {
283+ caption :
284+ data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
285+ . accessibility_caption ,
286+
287+ image :
288+ data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
289+ . image . uri ,
290+ }
291+ : data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
292+ . __typename == "Video"
293+ ? {
294+ permanlinkUrl :
295+ data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
296+ . permalink_url ,
297+
298+ playableVideo :
299+ data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
300+ . playable_url ,
301+
302+ playableUrlDash :
303+ data . unified_stories . edges [ 0 ] . node . attachments [ 0 ] . media
304+ . playable_url_dash ,
305+
306+ playableUrlHDString :
307+ data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
308+ . playableUrlHdString ,
309+
310+ playableUrlHD :
311+ data . unified_stories . edges [ i ] . node . attachments [ 0 ] . media
312+ . playable_url_quality_hd ,
313+ }
314+ : null ) ,
315+ } ;
316+ } ) ,
317+ } ;
318+
319+ // let data =
320+ // "__a=1&fb_dtsg=" +
321+ // dtsg +
322+ // "&variables=%7B%22bucketID%22%3A%22" +
323+ // bucketID +
324+ // "%22%2C%22initialLoad%22%3Afalse%2C%22scale%22%3A1%7D&doc_id=2586853698032602";
325+
326+ // let xhr = new XMLHttpRequest();
327+ // xhr.withCredentials = true;
328+ // xhr.addEventListener("readystatechange", function () {
329+ // if (this.readyState === 4) {
330+
331+ // }
332+ // });
333+
334+ // xhr.open("POST", "https://www.facebook.com/api/graphql/");
335+ // xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
336+ // xhr.send(body);
337+ } ,
179338 } ,
180339} ;
181340window . UsefulScriptGlobalPageContext = UsefulScriptGlobalPageContext ;
0 commit comments