Skip to content

Commit 93e37db

Browse files
committed
story info - wip
1 parent aa35fb2 commit 93e37db

File tree

6 files changed

+181
-279
lines changed

6 files changed

+181
-279
lines changed

popup/tabs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ const tabs = [
118118
s.fb_getTokenCampaigns,
119119
s.fb_getTokenFacebook,
120120
s.fb_getTokenMFacebook,
121-
s.fb_getTokenLocmai,
122121
createTitle("--- Get ID ---", "--- Lấy ID ---"),
123122
s.fb_getUid,
124123
s.fb_getPageId,

scripts/content-scripts/scripts/ufs_global_webpage_context.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,165 @@ const UsefulScriptGlobalPageContext = {
176176
decodeArrId(arrId) {
177177
return arrId[0] * 4294967296 + arrId[1];
178178
},
179+
getStoryBucketIdFromURL(url) {
180+
return url.match(/stories\/(\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 = /"DTSGInitialData",\[],{"token":"(.+?)"/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_user=(\d+)/)[1],
210+
() => {
211+
const regex = /c_user=(\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
};
181340
window.UsefulScriptGlobalPageContext = UsefulScriptGlobalPageContext;

scripts/fb_getTokenLocmai.js

Lines changed: 0 additions & 126 deletions
This file was deleted.

scripts/fb_moreReactionStory.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export default {
3737
if (!window.location.href.includes("facebook.com/stories")) return;
3838
if (!!document.querySelector(".ufs-more-react-story")) return;
3939

40-
const fb_dtsg = getFbdtsg();
41-
const user_id = getUserId();
40+
const fb_dtsg = UsefulScriptGlobalPageContext.Facebook.getFbdtsg();
41+
const user_id = UsefulScriptGlobalPageContext.Facebook.getUserId();
4242

4343
/* HTML template
4444
<div class="ufs-more-react-story">
@@ -90,7 +90,8 @@ export default {
9090

9191
let loading = 0;
9292
emojiLi.onclick = async function () {
93-
const storyId = getStoryId();
93+
const storyId =
94+
UsefulScriptGlobalPageContext.Facebook.getStoryId();
9495
try {
9596
if (!loading) emojiLi.classList.add("loading");
9697
loading++;
@@ -145,30 +146,6 @@ export default {
145146
floatingEmoji.remove();
146147
}, 2e3);
147148
}
148-
function getStoryId() {
149-
const htmlStory = document.getElementsByClassName(
150-
"xh8yej3 x1n2onr6 xl56j7k x5yr21d x78zum5 x6s0dn4"
151-
);
152-
return htmlStory[htmlStory.length - 1].getAttribute("data-id");
153-
}
154-
function getFbdtsg() {
155-
try {
156-
const regex = /"DTSGInitialData",\[],{"token":"(.+?)"/gm;
157-
const resp = regex.exec(document.documentElement.innerHTML);
158-
return resp[1];
159-
} catch (e) {
160-
return require("DTSGInitData").token;
161-
}
162-
}
163-
function getUserId() {
164-
try {
165-
const regex = /c_user=(\d+);/gm;
166-
const resp = regex.exec(document.cookie);
167-
return resp[1];
168-
} catch (e) {
169-
return require("RelayAPIConfigDefaults").actorID;
170-
}
171-
}
172149
function reactStory(user_id, fb_dtsg, story_id, message) {
173150
return new Promise(async (resolve, reject) => {
174151
const variables = {

0 commit comments

Comments
 (0)