Skip to content

Commit 8ef17e4

Browse files
committed
Merge branch 'dev'
2 parents b07afd6 + bac46a8 commit 8ef17e4

File tree

21 files changed

+2597
-425
lines changed

21 files changed

+2597
-425
lines changed
Loading
Loading
Loading
Loading
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { sharePostToGroup } from "./popup/helpers/facebook.js";
2+
import { randInt } from "./popup/helpers/utils.js";
3+
4+
console.log("background");
5+
6+
const logs = [];
7+
const sharePostToGroups = [
8+
// {
9+
// postUrl: "https://www.facebook.com/share/p/1phXqQ8TvxniRVsi/",
10+
// caption: "",
11+
// groups: [
12+
// "https://www.facebook.com/groups/311528245988035",
13+
// "311528245988035",
14+
// ],
15+
// waitMin: 5000,
16+
// waitMax: 20000,
17+
// timer: "2024-09-08T21:06",
18+
// },
19+
];
20+
21+
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
22+
if (request.action === "get_sharePostToGroups") {
23+
sendResponse(sharePostToGroups);
24+
} else if (request.action === "add_sharePostToGroups") {
25+
sharePostToGroups.push(request.data);
26+
sendResponse(sharePostToGroups);
27+
} else if (request.action === "remove_sharePostToGroups") {
28+
sharePostToGroups.splice(request.data?.index, 1);
29+
sendResponse(sharePostToGroups);
30+
} else if (request.action === "get_logs") {
31+
sendResponse(logs);
32+
} else if (request.action === "clear_logs") {
33+
logs.length = 0;
34+
sendResponse(logs);
35+
}
36+
});
37+
38+
function addLog(log) {
39+
logs.push({
40+
time: Date.now(),
41+
log: log,
42+
});
43+
}
44+
45+
setInterval(() => {
46+
for (let i = 0; i < sharePostToGroups.length; i++) {
47+
let job = sharePostToGroups[i];
48+
49+
if (job.done || job.sharing) continue;
50+
51+
if (job.running) {
52+
// sharing
53+
if (
54+
!job.nextShareTime ||
55+
Date.now() > new Date(job.nextShareTime).getTime()
56+
) {
57+
let groupUrl = job.groups[job.shareIndex];
58+
job.sharing = true;
59+
sharePostToGroup({
60+
postUrl: job.postUrl,
61+
groupUrl: groupUrl,
62+
note: job.caption || "",
63+
})
64+
.then((sharedUrl) => {
65+
console.log("share", groupUrl, job, sharedUrl);
66+
job.sharedUrls[job.shareIndex] = sharedUrl;
67+
addLog(
68+
`SHARE ${job.shareIndex + 1}/${job.groups.length}: shared ${
69+
job.postUrl
70+
} to ${groupUrl} => ${sharedUrl}`
71+
);
72+
})
73+
.catch((e) => {
74+
console.log(e);
75+
addLog(
76+
`FAIL SHARE ${job.shareIndex + 1}/${job.groups.length}: share ${
77+
job.postUrl
78+
} to ${groupUrl} failed ${e.message}`
79+
);
80+
})
81+
.finally(() => {
82+
job.shareIndex++;
83+
// check done
84+
if (job.shareIndex > job.groups.length - 1) {
85+
job.running = false;
86+
job.done = Date.now();
87+
addLog(
88+
`DONE: share ${job.postUrl} to ${job.groups.length} groups`
89+
);
90+
} else {
91+
job.nextShareTime =
92+
Date.now() + randInt(job.waitMin, job.waitMax);
93+
}
94+
job.sharing = false;
95+
});
96+
}
97+
98+
continue;
99+
}
100+
101+
// check start running
102+
if (Date.now() > new Date(job.timer).getTime()) {
103+
job.running = true;
104+
job.shareIndex = 0;
105+
job.sharedUrls = Array(job.groups.length).fill("");
106+
addLog(
107+
`START: share ${job.postUrl} to ${
108+
job.groups.length
109+
} groups: ${job.groups.join(", ")}`
110+
);
111+
}
112+
}
113+
}, 1000);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"manifest_version": 3,
3+
"name": "Facebook Group Extension",
4+
"description": "Quản lý nhóm facebook",
5+
"version": "1.0",
6+
"action": {
7+
"default_popup": "./popup/index.html"
8+
},
9+
"icons": {
10+
"16": "assets/icon_default_16.png",
11+
"48": "assets/icon_default_48.png",
12+
"128": "assets/icon_default_128.png"
13+
},
14+
"background": {
15+
"service_worker": "background.js",
16+
"type": "module"
17+
},
18+
"permissions": [
19+
"tabs",
20+
"cookies",
21+
"scripting",
22+
"declarativeNetRequest",
23+
"declarativeNetRequestFeedback",
24+
"declarativeNetRequestWithHostAccess"
25+
],
26+
"host_permissions": ["*://*/*", "<all_urls>"],
27+
"declarative_net_request": {
28+
"rule_resources": [
29+
{
30+
"id": "ruleset_1",
31+
"enabled": true,
32+
"path": "./rules.json"
33+
}
34+
]
35+
}
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Facebook Tools</title>
8+
9+
<link rel="stylesheet" href="style.css">
10+
</head>
11+
12+
<body>
13+
<h1>Tự động mời like page</h1>
14+
15+
<div class="input-container">
16+
<h3>Thời gian chờ (giây):</h3>
17+
<span><i>(ngẫu nhiên trong khoảng)</i></span><br />
18+
<div class="input-row">
19+
<input type="number" min="0" value="5" id="inputWaitMin" /> ➡️ <input type="number" min="0" value="20"
20+
id="inputWaitMax" />
21+
</div>
22+
</div>
23+
24+
<h3>Mời tối đa bao nhiêu người?</h3>
25+
<span><i>(nhập 0 để mời hết)</i></span><br />
26+
<input type="number" id="max-people" value="10">
27+
28+
<button class="button" id="start-btn">Bắt đầu</button>
29+
30+
<script src="main.js"></script>
31+
</body>
32+
33+
</html>

0 commit comments

Comments
 (0)