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