-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
fb_autoLike.js
220 lines (194 loc) · 6.04 KB
/
fb_autoLike.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { UfsGlobal } from "./content-scripts/ufs_global.js";
import { BADGES } from "./helpers/badge.js";
export default {
icon: '<i class="fa-solid fa-heart fa-lg"></i>',
name: {
en: "Auto like post on Facebook",
vi: "Tự động thích bài đăng Facebook",
},
description: {
en: `Auto like post on Facebook.
<ul>
<li>Support all post types (page, group, user, feed, ...)</li>
<li>Support bulk remove/add reactions</li>
<li>Support all reaction types</li>
</ul>`,
vi: `Tự động thả cảm xúc cho bài đăng trên Facebook.
<ul>
<li>Hỗ trợ mọi loại bài đăng (trang, nhóm, người dùng, new feed, ...)</li>
<li>Hỗ trợ gỡ/thêm cảm xúc hàng loạt</li>
<li>Hỗ trợ mọi loại cảm xúc</li>
</ul>`,
},
badges: [BADGES.new],
changeLogs: {
"2024-07-08": "init",
},
whiteList: ["https://*.facebook.com/*"],
pageScript: {
onClick: () => {
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
function focusTo(element) {
element.dispatchEvent(
new MouseEvent("pointerover", {
view: window,
bubbles: true,
cancelable: true,
})
);
}
function scrollToBottom() {
window.scrollTo(0, document.body.scrollHeight, { behavior: "smooth" });
}
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function isRunning(value) {
if (!(typeof value === "boolean"))
return window.ufs_fb_autoLike_running;
else window.ufs_fb_autoLike_running = value;
}
const Reactions = {
like: { vi: "Thích", en: "Like", emoji: "👍" },
love: { vi: "Yêu thích", en: "Love", emoji: "❤️" },
care: { vi: "Thương thương", en: "Care", emoji: "🤗" },
haha: { vi: "Haha", en: "Haha", emoji: "😂" },
wow: { vi: "Wow", en: "Wow", emoji: "😮" },
sad: { vi: "Buồn", en: "Sad", emoji: "😢" },
angry: { vi: "Phẫn nộ", en: "Angry", emoji: "😠" },
};
const Types = {
addReact: {
vi: "Bày tỏ cảm xúc",
en: "React",
name: "Thả cảm xúc - Add reaction",
},
removeReact: {
vi: "Gỡ ",
en: "Remove ",
name: "Gỡ cảm xúc - Remove reaction",
},
};
async function startAutoLike(
type = Types.addReact,
reaction = Reactions.love,
maxPosts = Infinity
) {
isRunning(true);
const notify = UfsGlobal.DOM.notify({
msg: "Đang chuẩn bị ...",
duration: 999999,
});
let count = 0;
const btns = [];
const unobserver = UfsGlobal.DOM.onElementsAdded(
["en", "vi"]
.map((l) =>
type === Types.removeReact
? Object.values(Reactions).map(
(r) =>
`[aria-label='${type[l]}${r[l]}']:not(li *):not([hidden] *)`
)
: `[aria-label='${type[l]}']:not(li *)`
)
.flat()
.join(", "),
(nodes) => {
btns.push(...nodes);
}
);
let scrollTried = 0;
while (true) {
if (!isRunning()) {
alert("Stopped Auto react !\n\nĐã dừng tự động thích!");
break;
}
if (!btns.length) {
scrollTried++;
if (scrollTried > 50) break;
notify.setText("Scrolling to bottom... " + scrollTried, 99999);
scrollToBottom();
await sleep(2000);
continue;
}
scrollTried = 0;
const btn = btns.shift();
btn.scrollIntoView({
block: "center",
behavior: "smooth",
});
let waitFor = rand(1000, 4000);
count++;
if (count >= maxPosts) break;
notify.setText(
type.name +
": " +
count +
"/" +
(count + btns.length) +
" - waiting: " +
(waitFor / 1000).toFixed(1) +
"s",
99999
);
await sleep(waitFor);
btn.click();
if (type === Types.addReact) {
await sleep(500);
let reactBtn = document.querySelector(
[reaction.en, reaction.vi]
.map((_) => `[aria-label='${_}']`)
.join(", ")
);
if (reactBtn) {
focusTo(reactBtn);
await sleep(100);
reactBtn.click();
await sleep(100);
}
}
}
unobserver?.();
let text = type.name + ": " + count + " posts";
notify.setText(text, 5000);
isRunning(false);
alert(text);
}
if (isRunning()) {
return isRunning(false);
}
const typeIndex = prompt(
"Bạn muốn?\n" +
Object.entries(Types)
.map(([key, value], i) => i + ": " + value.name)
.join("\n"),
0
);
let selectedType = Types[Object.keys(Types)[typeIndex]];
let selectedReact;
if (typeIndex === null || !selectedType) return;
if (typeIndex == 0) {
let reactIndex = prompt(
"Chọn reaction:\n" +
Object.entries(Reactions)
.map(
([key, value], i) =>
i + ": " + value.emoji + " " + value.en + " - " + value.vi
)
.join("\n"),
1
);
selectedReact = Reactions[Object.keys(Reactions)[reactIndex]];
if (reactIndex == null || !selectedReact) return;
}
let max = prompt(
"Thả bao nhiêu bài post? - Max post?: (0 = tất cả/all) ",
0
);
if (max == null) return;
if (max == 0) max = Infinity;
else max = parseInt(max);
startAutoLike(selectedType, selectedReact, max);
},
},
};