MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / start

Function start

scripts/fb_autoRemoveSpamPostGroup_main.js:98–210  ·  view source on GitHub ↗
(action, maxPosts, waitMin, waitMax)

Source from the content-addressed store, hash-verified

96}
97
98function start(action, maxPosts, waitMin, waitMax) {
99 const selector =
100 action == 1
101 ? '[role="main"] [aria-label="Đăng"]'
102 : '[role="main"] [aria-label="Từ chối"]';
103
104 if (maxPosts == 0) maxPosts = Infinity;
105
106 const btns = Array.from(document.querySelectorAll(selector));
107
108 if (!btns.length) {
109 alert("Không tìm thấy bài nào");
110 return;
111 }
112
113 onElementsAdded(selector, (nodes) => {
114 for (let node of nodes) {
115 if (btns.includes(node)) continue;
116 btns.push(node);
117 }
118 });
119
120 async function main() {
121 window.fb_group_ext = {
122 action,
123 running: true,
124 nextExecuteTime: 0,
125 stop: false,
126 count: 0,
127 };
128
129 while (window.fb_group_ext.count < maxPosts && !window.fb_group_ext.stop) {
130 if (btns.length > 0) {
131 const btn = btns.shift();
132
133 btn.scrollIntoView({ block: "center", behavior: "smooth" });
134 console.log("click", btn);
135 btn.click();
136
137 window.fb_group_ext.count++;
138 const waitTime = ranInt(waitMin, waitMax);
139 window.fb_group_ext.nextExecuteTime = Date.now() + waitTime;
140 await sleep(waitTime, () => window.fb_group_ext.stop);
141 } else {
142 // scroll to end
143 window.scrollTo(0, document.body.scrollHeight);
144 // wait for load more
145 await sleep(1000);
146 }
147 }
148
149 window.fb_group_ext.running = false;
150 alert("Duyệt xong " + window.fb_group_ext.count + " bài");
151 }
152
153 main();
154
155 function ranInt(min, max) {

Callers

nothing calls this directly

Calls 2

onElementsAddedFunction · 0.70
mainFunction · 0.70

Tested by

no test coverage detected