Skip to content

Commit 4d7e01f

Browse files
committed
WIP
1 parent 14f68c8 commit 4d7e01f

File tree

10 files changed

+233
-8
lines changed

10 files changed

+233
-8
lines changed
Binary file not shown.

scripts/backup/ext/fb-group-ext/manifest.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
"48": "assets/icon_default_48.png",
1212
"128": "assets/icon_default_128.png"
1313
},
14-
"permissions": ["tabs", "scripting"],
15-
"host_permissions": ["*://*/*", "<all_urls>"]
14+
"permissions": [
15+
"tabs",
16+
"cookies",
17+
"scripting",
18+
"declarativeNetRequest",
19+
"declarativeNetRequestFeedback",
20+
"declarativeNetRequestWithHostAccess"
21+
],
22+
"host_permissions": ["*://*/*", "<all_urls>"],
23+
"declarative_net_request": {
24+
"rule_resources": [
25+
{
26+
"id": "ruleset_1",
27+
"enabled": true,
28+
"path": "./rules.json"
29+
}
30+
]
31+
}
1632
}

scripts/backup/ext/fb-group-ext/popup/auto_duyet_bai_group/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ async function main() {
6060
// check is running
6161
(async function checkIsRunning() {
6262
const state = await getCurrentState(tab);
63-
const { running, nextExecuteTime, count } = state || {};
63+
const { running, nextExecuteTime, count, action } = state || {};
6464
if (running) {
6565
startBtn.innerHTML =
6666
"Đang " +
67-
(radioAction[0].checked ? "đăng" : "xoá") +
67+
(action === 1 ? "đăng" : "từ chối") +
6868
"... " +
6969
count +
7070
" bài (chờ " +
@@ -119,6 +119,7 @@ function start(action, maxPosts, waitMin, waitMax) {
119119

120120
async function main() {
121121
window.fb_group_ext = {
122+
action,
122123
running: true,
123124
nextExecuteTime: 0,
124125
stop: false,

scripts/backup/ext/fb-group-ext/popup/auto_gioihan_member/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,43 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Auto giới hạn members</title>
8+
9+
<style>
10+
html,
11+
body {
12+
background: #333;
13+
color: #eee;
14+
display: flex;
15+
justify-content: center;
16+
align-items: center;
17+
flex-direction: column;
18+
}
19+
20+
textarea {
21+
background: #444;
22+
color: #eee;
23+
padding: 10px;
24+
font-size: 16px;
25+
}
26+
27+
button {
28+
padding: 5px 10px;
29+
margin: 10px;
30+
cursor: pointer;
31+
}
32+
</style>
833
</head>
934

1035
<body>
1136
<h1>Auto giới hạn members</h1>
1237

38+
<textarea name="data" id="data" rows="10" cols="50"
39+
placeholder="Nhập dữ liệu vào đây theo từng dòng: uid|ngày hết hạn|group id">100040851258332|2024-08-28|2138246213171561</textarea>
40+
41+
<button>Bắt đầu</button>
42+
43+
<textarea name="result" id="result" cols="80" rows="20" placeholder="Kết quả sẽ hiện ở đây" disabled></textarea>
44+
1345
<script type="module" src="main.js"></script>
1446
</body>
1547

scripts/backup/ext/fb-group-ext/popup/auto_gioihan_member/main.js

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,67 @@
1-
import { fetchGraphQl } from "../helpers/facebook";
1+
import { fetchGraphQl, findDataObject, getMyUid } from "../helpers/facebook.js";
2+
import { sleep } from "../helpers/utils.js";
3+
4+
async function main(groupIds = [], excludeUids = []) {
5+
// getAllMemberUidHavePendingPosts({
6+
// groupId: "2138246213171561",
7+
// onProgress: async ({ current, all }) => {
8+
// console.log(current);
9+
// },
10+
// });
11+
12+
let stop = false;
13+
for (let groupId of groupIds) {
14+
}
15+
}
16+
main();
17+
18+
async function getAllMemberUidHavePendingPosts({ groupId, onProgress }) {
19+
const memUids = new Set();
20+
const allMembers = [];
21+
await getAllPendingPosts({
22+
groupId,
23+
onProgress: async ({ all, current }) => {
24+
const newMem = current
25+
?.map?.((d) => d?.node?.comet_sections?.content?.story?.actors || [])
26+
.flat()
27+
.filter((u) => {
28+
if (!u) return false;
29+
if (memUids.has(u)) return false;
30+
memUids.add(u);
31+
return true;
32+
});
33+
34+
allMembers.push(...newMem);
35+
36+
await onProgress?.({
37+
current: newMem,
38+
all: allMembers,
39+
});
40+
},
41+
});
42+
return allMembers;
43+
}
44+
45+
async function getAllPendingPosts({ groupId, onProgress, cursor = "" }) {
46+
const allPosts = [];
47+
while (true) {
48+
try {
49+
const { edges, page_info } = await getPendingPosts(groupId, cursor);
50+
if (!page_info?.has_next_page || edges.length === 0) break;
51+
allPosts.push(...edges);
52+
await onProgress?.({
53+
current: edges,
54+
all: allPosts,
55+
});
56+
cursor = page_info.end_cursor;
57+
await sleep(500);
58+
} catch (e) {
59+
console.log(e);
60+
break;
61+
}
62+
}
63+
return allPosts;
64+
}
265

366
async function getPendingPosts(groupId, cursor = "") {
467
const res = await fetchGraphQl({
@@ -27,7 +90,64 @@ async function getPendingPosts(groupId, cursor = "") {
2790
},
2891
doc_id: "8078135725563420",
2992
});
30-
console.log(res);
93+
const json = JSON.parse(res.split("\n")[0]);
94+
// console.log(json);
95+
const { edges, page_info } = findDataObject(json) || {};
96+
return { edges, page_info };
97+
}
98+
99+
async function limitMember({ groupId, uid, actorId = "", willLimit = true }) {
100+
const res = await fetchGraphQl({
101+
fb_api_req_friendly_name: "GroupsCometMemberSetContentControlsMutation",
102+
variables: {
103+
input: {
104+
admin_notes: "",
105+
group_id: groupId,
106+
rate_limit_settings: [
107+
{
108+
duration: 86400,
109+
limit_per_time_period: 10,
110+
limit_type: "RATE_LIMIT_COMMENT_IN_GROUP",
111+
should_rate_limit_target: willLimit,
112+
time_period: 3600,
113+
},
114+
{
115+
duration: 86400,
116+
limit_per_time_period: 2,
117+
limit_type: "RATE_LIMIT_POST_IN_GROUP",
118+
should_rate_limit_target: willLimit,
119+
time_period: 86400,
120+
},
121+
],
122+
selected_rules: [],
123+
share_feedback: false,
124+
target_user_id: uid,
125+
actor_id: actorId || (await getMyUid()),
126+
client_mutation_id: "33", // auto increment??
127+
},
128+
memberID: uid,
129+
},
130+
doc_id: "7103666173041398",
131+
});
132+
}
133+
134+
async function getCurrentLimit({ groupId, uid }) {
135+
const res = await fetchGraphQl({
136+
fb_api_req_friendly_name:
137+
"GroupsCometMembersSetMemberContentControlDialogQuery",
138+
variables: {
139+
groupID: groupId,
140+
memberID: uid,
141+
scale: 1,
142+
},
143+
doc_id: "7779093765537808",
144+
});
145+
146+
const json = JSON.parse(res);
147+
console.log(json);
31148
}
32149

33-
getPendingPosts();
150+
// getCurrentLimit({
151+
// groupId: "2138246213171561",
152+
// uid: "100024071323401",
153+
// });

scripts/backup/ext/fb-group-ext/popup/auto_gioihan_member/style.css

Whitespace-only changes.

scripts/backup/ext/fb-group-ext/popup/helpers/facebook.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
const CACHED = {
2+
uid: null,
23
fb_dtsg: null,
34
};
45

6+
export async function getMyUid() {
7+
if (CACHED.uid) return CACHED.uid;
8+
const d = await runExtFunc("chrome.cookies.get", [
9+
{ url: "https://www.facebook.com", name: "c_user" },
10+
]);
11+
CACHED.uid = d?.value;
12+
return CACHED.uid;
13+
}
14+
515
export async function fetchGraphQl(params, url) {
616
let query = "";
717
if (typeof params === "string") query = "&q=" + encodeURIComponent(params);
@@ -80,3 +90,18 @@ export async function getFbDtsg() {
8090
CACHED.fb_dtsg = dtsg || null;
8191
return CACHED.fb_dtsg;
8292
}
93+
94+
export function findDataObject(object) {
95+
if (!object) return null;
96+
97+
// Check if the current object has edges and page_info properties
98+
if (object.edges && object.page_info) return object;
99+
100+
for (let key in object) {
101+
if (typeof object[key] === "object" && object[key] !== null) {
102+
let found = findDataObject(object[key]);
103+
if (found) return found;
104+
}
105+
}
106+
return null;
107+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function sleep(time) {
2+
return new Promise((resolve) => {
3+
setTimeout(resolve, time);
4+
});
5+
}

scripts/backup/ext/fb-group-ext/popup/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<h1>Faecbook tools</h1>
3232

3333
<a href="./auto_duyet_bai_group/index.html">📝 Auto duyệt bài group</a>
34-
<a href="./auto_gioihan_member/index.html">🙋🏻‍♂️ Auto giới hạn members</a>
34+
<a href="./auto_gioihan_member/index.html" target="_blank">🙋🏻‍♂️ Auto giới hạn members</a>
3535
</body>
3636

3737
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"id": 1,
4+
"priority": 1,
5+
"action": {
6+
"type": "modifyHeaders",
7+
"requestHeaders": [
8+
{
9+
"header": "referer",
10+
"operation": "set",
11+
"value": "https://www.facebook.com"
12+
},
13+
{
14+
"header": "origin",
15+
"operation": "set",
16+
"value": "https://www.facebook.com"
17+
}
18+
]
19+
},
20+
"condition": {
21+
"domain": "extension://*",
22+
"urlFilter": "https://www.facebook.com",
23+
"resourceTypes": ["xmlhttprequest"]
24+
}
25+
}
26+
]

0 commit comments

Comments
 (0)