Skip to content

Commit

Permalink
fix: 点赞跳过加上英文title判断
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Apr 3, 2024
1 parent 15a6ba9 commit 36e05fb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
18 changes: 16 additions & 2 deletions external.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// 更新初始数据的函数
function updateInitialData() {
localStorage.setItem("read", "true"); // 开始时自动滚动关闭
localStorage.setItem("autoLikeEnabled", "false"); //默认关闭自动点赞
localStorage.setItem("autoLikeEnabled", "true"); //默认关闭自动点赞
console.log("执行了初始数据更新操作");
}
const delay = 2000; // 滚动检查的间隔(毫秒)
Expand Down Expand Up @@ -198,6 +198,8 @@
);
}
}
// 从localStorage获取当前的点击计数,如果不存在则初始化为0
let clickCounter = parseInt(localStorage.getItem("clickCounter") || "0", 10);
function autoLike() {
// 寻找所有的discourse-reactions-reaction-button
const buttons = document.querySelectorAll(
Expand All @@ -206,7 +208,11 @@

// 逐个点击找到的按钮
buttons.forEach((button, index) => {
if (button.title !== "点赞此帖子") {
if (
button.title !== "点赞此帖子" ||
button.title !== "Like this post" ||
clickCounter >= 50
) {
return;
}

Expand All @@ -215,6 +221,14 @@
// 模拟点击
button.click();
console.log(`Clicked button ${index + 1}`);
clickCounter++; // 更新点击计数器
// 将新的点击计数存储到localStorage
localStorage.setItem("clickCounter", clickCounter.toString());
// 如果点击次数达到50次,则设置点赞变量为false
if (clickCounter === 50) {
console.log("Reached 50 likes, setting the like variable to false.");
localStorage.setItem("autoLikeEnabled", "false"); // 使用localStorage存储点赞变量状态
}
}, index * 1000); // 这里的1000毫秒是两次点击之间的间隔,可以根据需要调整
});
}
Expand Down
6 changes: 5 additions & 1 deletion index_passage_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@

// 逐个点击找到的按钮
buttons.forEach((button, index) => {
if (button.title !== "点赞此帖子" || clickCounter >= 50) {
if (
button.title !== "点赞此帖子" ||
button.title !== "Like this post" ||
clickCounter >= 50
) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"dotenv": "^16.4.5",
"puppeteer": "^22.6.1"
}
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions puppeteer_c.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require("fs");

const path = require("path");
const puppeteer = require("puppeteer");
require("dotenv").config();

(async () => {
//随机等待时间
Expand Down Expand Up @@ -34,7 +36,9 @@ const puppeteer = require("puppeteer");
await delayClick(500); // 延迟500毫秒
// 清空输入框并输入用户名
await page.click("#login-account-name", { clickCount: 3 });
await page.type("#login-account-name", process.env.USERNAME, { delay: 100 }); // 输入时在每个按键之间添加额外的延迟
await page.type("#login-account-name", process.env.USERNAMELINUXDO, {
delay: 100,
}); // 输入时在每个按键之间添加额外的延迟

// 等待密码输入框加载
await page.waitForSelector("#login-account-password");
Expand All @@ -55,8 +59,6 @@ const puppeteer = require("puppeteer");
await page.click("#login-button");

//真正执行阅读脚本
await page.goto("https://linux.do/t/topic/13716/100");

// 读取外部脚本文件的内容
const externalScriptPath = path.join(__dirname, "external.js");
const externalScript = fs.readFileSync(externalScriptPath, "utf8");
Expand All @@ -66,4 +68,5 @@ const puppeteer = require("puppeteer");
const [scriptToEval] = args;
eval(scriptToEval);
}, externalScript);
await page.goto("https://linux.do/t/topic/13716/100");
})();

0 comments on commit 36e05fb

Please sign in to comment.