Skip to content

Commit 15a6ba9

Browse files
committed
feat: 设置点赞上限
1 parent 8952911 commit 15a6ba9

File tree

4 files changed

+19
-333
lines changed

4 files changed

+19
-333
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
.env
12
node_modules/

index_passage_list.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@
198198
);
199199
}
200200
}
201+
// 从localStorage获取当前的点击计数,如果不存在则初始化为0
202+
let clickCounter = parseInt(localStorage.getItem("clickCounter") || "0", 10);
201203
function autoLike() {
202204
// 寻找所有的discourse-reactions-reaction-button
203205
const buttons = document.querySelectorAll(
@@ -206,7 +208,7 @@
206208

207209
// 逐个点击找到的按钮
208210
buttons.forEach((button, index) => {
209-
if (button.title !== "点赞此帖子") {
211+
if (button.title !== "点赞此帖子" || clickCounter >= 50) {
210212
return;
211213
}
212214

@@ -215,6 +217,14 @@
215217
// 模拟点击
216218
button.click();
217219
console.log(`Clicked button ${index + 1}`);
220+
clickCounter++; // 更新点击计数器
221+
// 将新的点击计数存储到localStorage
222+
localStorage.setItem("clickCounter", clickCounter.toString());
223+
// 如果点击次数达到50次,则设置点赞变量为false
224+
if (clickCounter === 50) {
225+
console.log("Reached 50 likes, setting the like variable to false.");
226+
localStorage.setItem("autoLikeEnabled", "false"); // 使用localStorage存储点赞变量状态
227+
}
218228
}, index * 1000); // 这里的1000毫秒是两次点击之间的间隔,可以根据需要调整
219229
});
220230
}

puppeteer_c.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ const puppeteer = require("puppeteer");
3434
await delayClick(500); // 延迟500毫秒
3535
// 清空输入框并输入用户名
3636
await page.click("#login-account-name", { clickCount: 3 });
37-
await page.type("#login-account-name", "hahaha2", { delay: 100 }); // 输入时在每个按键之间添加额外的延迟
37+
await page.type("#login-account-name", process.env.USERNAME, { delay: 100 }); // 输入时在每个按键之间添加额外的延迟
3838

3939
// 等待密码输入框加载
4040
await page.waitForSelector("#login-account-password");
4141
// 模拟人类在输入用户名后的短暂停顿
4242
await delayClick(500);
4343
// 清空输入框并输入密码
4444
await page.click("#login-account-password", { clickCount: 3 });
45-
await page.type("#login-account-password", "BfdSGt}F4!5pLHt", { delay: 100 });
45+
await page.type("#login-account-password", process.env.PASSWORD, {
46+
delay: 100,
47+
});
4648

4749
// 模拟人类在输入完成后思考的短暂停顿
4850
await delayClick(1000);
@@ -52,6 +54,9 @@ const puppeteer = require("puppeteer");
5254
await delayClick(500); // 模拟在点击登录按钮前的短暂停顿
5355
await page.click("#login-button");
5456

57+
//真正执行阅读脚本
58+
await page.goto("https://linux.do/t/topic/13716/100");
59+
5560
// 读取外部脚本文件的内容
5661
const externalScriptPath = path.join(__dirname, "external.js");
5762
const externalScript = fs.readFileSync(externalScriptPath, "utf8");

puppeteer_control.js

Lines changed: 0 additions & 330 deletions
This file was deleted.

0 commit comments

Comments
 (0)