Skip to content

Commit 7ee1c2c

Browse files
committed
get fb post reaction count
1 parent 4ed5a33 commit 7ee1c2c

File tree

7 files changed

+132
-14
lines changed

7 files changed

+132
-14
lines changed

popup/tabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ const tabs = [
313313
s.fb_toggleNewFeed,
314314
s.fb_stopNewFeed,
315315
s.fb_blockSeenStory,
316+
s.fb_getPostReactionCount,
316317
s.fb_whoIsTyping,
317318
// s.fb_blockSeenAndTyping,
318319
createTitle("--- Statistic ---", "--- Thống kê ---"),

scripts/_index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,4 @@ export { default as fb_stopNewFeed } from "./fb_stopNewFeed.js";
167167
export { default as github_HTMLPreview } from "./github_HTMLPreview.js";
168168
export { default as showImageOnHoverLink } from "./showImageOnHoverLink.js";
169169
export { default as fb_allInOne } from "./fb_allInOne.js";
170+
export { default as fb_getPostReactionCount } from "./fb_getPostReactionCount.js";

scripts/content-scripts/ufs_global.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ function notify({
530530
}
531531
${styleText || ""}
532532
`;
533-
div.textContent = msg;
533+
div.innerHTML = createTrustedHtml(msg);
534534
(document.body || document.documentElement).appendChild(div);
535535

536536
let timeouts = [];
@@ -563,7 +563,7 @@ function notify({
563563
},
564564
setText(text) {
565565
if (div) {
566-
div.textContent = text;
566+
div.innerHTML = createTrustedHtml(text);
567567
return true;
568568
}
569569
return false;

scripts/fb_downloadWatchingVideo.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ export default {
2525
);
2626
try {
2727
let listVideoId = await shared.getListVideoIdInWebsite();
28-
let watchingVideoId = listVideoId?.[0];
29-
if (!watchingVideoId) throw Error("Không tìm thấy video nào");
28+
if (!listVideoId?.length > 0) throw Error("Không tìm thấy video");
3029

31-
setLoadingText("Đang lấy token dtsg...");
32-
let dtsg = await fb_videoDownloader.getDtsg();
30+
for (let videoId of listVideoId) {
31+
if (!videoId) continue;
3332

34-
setLoadingText("Đang tìm video url...");
35-
let videoUrl = await fb_videoDownloader.getLinkFbVideo(
36-
watchingVideoId,
37-
dtsg
38-
);
33+
setLoadingText("Đang lấy token dtsg...");
34+
let dtsg = await fb_videoDownloader.getDtsg();
35+
36+
setLoadingText("Đang tìm video url...");
37+
let videoUrl = await fb_videoDownloader.getLinkFbVideo(videoId, dtsg);
38+
39+
if (!videoUrl) continue;
3940

40-
if (videoUrl) {
4141
UfsGlobal.Utils.downloadURL(videoUrl, "fb_video.mp4");
42-
} else throw Error("Không tìm được video link");
42+
}
4343
} catch (e) {
4444
alert("ERROR: " + e);
4545
} finally {
8.27 KB
Loading

scripts/fb_getPostReactionCount.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { UfsGlobal } from "./content-scripts/ufs_global.js";
2+
import { fetchGraphQl, getFbdtsg } from "./fb_GLOBAL.js";
3+
4+
export default {
5+
icon: '<i class="fa-solid fa-thumbs-up fa-lg"></i>',
6+
name: {
7+
en: "Show facebook post reaction count",
8+
vi: "Hiện tổng lượt thích bài viết facebook",
9+
},
10+
description: {
11+
en: "Show total reaction count on facebook posts when hover mouse over post's reaction section",
12+
vi: "Hiện tổng lượt thích bài viết khi đưa chuột vào xem lượt thích.",
13+
img: "/scripts/fb_getPostReactionCount.jpg",
14+
},
15+
16+
changeLogs: {
17+
"2024-06-25": "init",
18+
},
19+
20+
whiteList: ["https://*.facebook.com/*"],
21+
22+
pageScript: {
23+
onDocumentStart: (details) => {
24+
const CACHED = {};
25+
const ReactionId = {
26+
"👍": "1635855486666999",
27+
"💖": "1678524932434102",
28+
"🥰": "613557422527858",
29+
"😆": "115940658764963",
30+
"😲": "478547315650144",
31+
"😔": "908563459236466",
32+
"😡": "444813342392137",
33+
};
34+
35+
const getPostReactionsCount = async (id, reactionId) => {
36+
const res = await fetchGraphQl(
37+
{
38+
fb_api_caller_class: "RelayModern",
39+
fb_api_req_friendly_name: "CometUFIReactionIconTooltipContentQuery",
40+
variables: {
41+
feedbackTargetID: id,
42+
reactionID: reactionId,
43+
},
44+
doc_id: "6235145276554312",
45+
},
46+
await getFbdtsg()
47+
);
48+
const json = JSON.parse(res || "{}");
49+
return json?.data?.feedback?.reactors?.count || 0;
50+
};
51+
52+
const getTotalPostReactionCount = async (id) => {
53+
const { setText, closeAfter } = UfsGlobal.DOM.notify({
54+
msg: "Đang đếm số lượng reaction...",
55+
duration: 10000,
56+
});
57+
58+
let res;
59+
if (CACHED[id]) {
60+
res = CACHED[id];
61+
} else {
62+
res = {
63+
total: 0,
64+
each: {},
65+
};
66+
for (let [name, reactionId] of Object.entries(ReactionId)) {
67+
const count = await getPostReactionsCount(id, reactionId);
68+
res.total += count;
69+
res.each[name] = count;
70+
setText(`Đang đếm số lượng reaction ${name}... Tổng: ${res.total}`);
71+
}
72+
CACHED[id] = res;
73+
}
74+
75+
setText(
76+
"<p style='color:white;font-size:20px;padding:0;margin:0'>Tổng " +
77+
res.total +
78+
" reaction.<br/>Bao gồm " +
79+
Object.entries(res.each)
80+
.filter(([key, value]) => value > 0)
81+
.map(([key, value]) => `${value}${key}`)
82+
.join(", ") +
83+
"</p>"
84+
);
85+
closeAfter(10000);
86+
};
87+
88+
const originalXMLSend = XMLHttpRequest.prototype.send;
89+
XMLHttpRequest.prototype.send = function () {
90+
let s = arguments[0]?.toString() || "";
91+
if (s.includes("CometUFIReactionsCountTooltipContentQuery")) {
92+
console.log(this);
93+
const original = this.onreadystatechange;
94+
this.onreadystatechange = function () {
95+
if (this.readyState == 4) {
96+
try {
97+
const json = JSON.parse(this.responseText);
98+
if (
99+
json?.data?.feedback?.reaction_display_config
100+
?.reaction_display_strategy == "HIDE_COUNTS"
101+
) {
102+
const id = json.data.feedback.id;
103+
getTotalPostReactionCount(id);
104+
}
105+
} catch (err) {
106+
console.log(err);
107+
}
108+
}
109+
original.apply(this, arguments);
110+
};
111+
}
112+
originalXMLSend.apply(this, arguments);
113+
};
114+
},
115+
},
116+
};

scripts/fb_stopNewFeed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function stopNewFeed() {
7272
};
7373

7474
let enabled = true;
75-
var originalXMLSend = XMLHttpRequest.prototype.send;
75+
const originalXMLSend = XMLHttpRequest.prototype.send;
7676
XMLHttpRequest.prototype.send = function () {
7777
let s = arguments[0]?.toString() || "";
7878

0 commit comments

Comments
 (0)