Skip to content

Commit

Permalink
refractor: 合并为一个脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Jan 15, 2025
1 parent 8d684a7 commit 90c988b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
8 changes: 5 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# 以下的内容都可以在.env.local里进行放置,它的优先级会更高,同时不会上传到github仓库

#支持多账户,使用逗号分隔每个账户,密码中有特殊字符可能会导致识别失败
USERNAMES=lidenghui
PASSWORDS=.JSn6qQPKjsLx@@ # 密码外面要加上双引号,密码内部如果有双引号,需要加上转义字符,linux使用\转义,Windows使用"转义 (注意GitHub action不需要增加处理,也不需要加引号)
WEBSITE=https://linux.do # 需要阅读的网站,支持后面那些:https://meta.discourse.org, https://meta.appinn.net, https://community.openai.com
PASSWORDS=.JSn6qQPKjsLx@@ # 密码外面要加上双引号,密码内部如果有双引号,需要加上转义字符,linux使用\转义,Windows使用"转义 (注意GitHub action不需要增加处理,也不需要加引号)
WEBSITE=https://linux.do # 需要阅读的网站,支持后面那些:https://meta.discourse.org, https://meta.appinn.net, https://community.openai.com
#运行时间,单位为分钟
RUN_TIME_LIMIT_MINUTES=20
# 电报通知报错信息(可不填)
TELEGRAM_BOT_TOKEN=
TELEGRAM_CHAT_ID=
# 自动点赞用户id(只有在cron_bypassCF_likeUser有用,也就是自动点赞特定用户的时候有用)
# 自动点赞用户id(只有在命令行配置环境变量 LIKE_SPECIFIC_USER=true 的时候有用,或者也可以在这里配置,我为了能在action中设置环境变量,所以这里没有设置)
SPECIFIC_USER=14790897
# 健康探针端口
HEALTH_PORT=8081
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cron_bypassCF_likeUser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ jobs:
shell: bash

- name: Run a script
run: node bypasscf_likeUser.js --USERNAMES "$USERNAMES" --PASSWORDS "$PASSWORDS" --WEBSITE "$WEBSITE"
run: LIKE_SPECIFIC_USER=true node bypasscf.js --USERNAMES "$USERNAMES" --PASSWORDS "$PASSWORDS" --WEBSITE "$WEBSITE"
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ npm install
# 自动阅读随机点赞
node .\bypasscf.js
# 自动点赞特定用户
node .\bypasscf_likeUser.js
## windows
set LIKE_SPECIFIC_USER=true && node .\bypasscf.js
## powershell
$env:LIKE_SPECIFIC_USER = "true"
node .\bypasscf.js
## linux
LIKE_SPECIFIC_USER=true node ./bypasscf.js
```

#### Linux 额外安装以下包,运行命令相同
Expand Down
19 changes: 14 additions & 5 deletions bypasscf.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const delayBetweenInstances = 10000;
const totalAccounts = usernames.length; // 总的账号数
const delayBetweenBatches =
runTimeLimitMillis / Math.ceil(totalAccounts / maxConcurrentAccounts);

const isLikeSpecificUser = process.env.LIKE_SPECIFIC_USER || "false";
let bot;
if (token && chatId) {
bot = new TelegramBot(token);
Expand Down Expand Up @@ -233,10 +233,18 @@ async function launchBrowserForUser(username, password) {
}

//真正执行阅读脚本
const externalScriptPath = path.join(
dirname(fileURLToPath(import.meta.url)),
"index.js"
);
let externalScriptPath;
if (isLikeSpecificUser === "true") {
externalScriptPath = path.join(
dirname(fileURLToPath(import.meta.url)),
"index_likeUser.js"
);
} else {
externalScriptPath = path.join(
dirname(fileURLToPath(import.meta.url)),
"index.js"
);
}
const externalScript = fs.readFileSync(externalScriptPath, "utf8");

// 在每个新的文档加载时执行外部脚本
Expand Down Expand Up @@ -368,6 +376,7 @@ async function login(page, username, password, retryCount = 3) {
} else {
if (retryCount > 0) {
console.log("Retrying login...");
await page.reload({ waitUntil: "domcontentloaded" });
await delayClick(2000); // 增加重试前的延迟
return await login(page, username, password, retryCount - 1);
} else {
Expand Down

0 comments on commit 90c988b

Please sign in to comment.