Skip to content

Commit f57d512

Browse files
committed
fix: env.local后才能读取环境变量,page.evaluate变量必须从外部显示的传入, 因为在浏览器上下文它是读取不了的
1 parent a3fc1d0 commit f57d512

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

bypasscf.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ import { dirname, join } from "path";
88
import TelegramBot from "node-telegram-bot-api";
99

1010
dotenv.config();
11-
const token = process.env.TELEGRAM_BOT_TOKEN;
12-
const chatId = process.env.TELEGRAM_CHAT_ID;
13-
let bot;
14-
if (token && chatId) {
15-
bot = new TelegramBot(token);
16-
}
17-
function sendToTelegram(message) {
18-
bot
19-
.sendMessage(chatId, message)
20-
.then(() => {
21-
console.log("Telegram message sent successfully");
22-
})
23-
.catch((error) => {
24-
console.error("Error sending Telegram message:", error);
25-
});
26-
}
2711

2812
// 读取以分钟为单位的运行时间限制
2913
const runTimeLimitMinutes = process.env.RUN_TIME_LIMIT_MINUTES || 15;
@@ -60,6 +44,23 @@ if (fs.existsSync(".env.local")) {
6044
"Using .env file to supply config environment variables, you can create a .env.local file to overwrite defaults, it doesn't upload to git"
6145
);
6246
}
47+
const token = process.env.TELEGRAM_BOT_TOKEN;
48+
const chatId = process.env.TELEGRAM_CHAT_ID;
49+
let bot;
50+
if (token && chatId) {
51+
bot = new TelegramBot(token);
52+
}
53+
function sendToTelegram(message) {
54+
bot
55+
.sendMessage(chatId, message)
56+
.then(() => {
57+
console.log("Telegram message sent successfully");
58+
})
59+
.catch((error) => {
60+
console.error("Error sending Telegram message:", error);
61+
});
62+
}
63+
6364
// 从环境变量解析用户名和密码
6465
const usernames = process.env.USERNAMES.split(",");
6566
const passwords = process.env.PASSWORDS.split(",");

bypasscf_likeUser.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@ import { dirname, join } from "path";
88
import TelegramBot from "node-telegram-bot-api";
99

1010
dotenv.config();
11-
const token = process.env.TELEGRAM_BOT_TOKEN;
12-
const chatId = process.env.TELEGRAM_CHAT_ID;
13-
const specificUser = process.env.SPECIFIC_USER || "14790897";
14-
let bot;
15-
if (token && chatId) {
16-
bot = new TelegramBot(token);
17-
}
18-
function sendToTelegram(message) {
19-
bot
20-
.sendMessage(chatId, message)
21-
.then(() => {
22-
console.log("Telegram message sent successfully");
23-
})
24-
.catch((error) => {
25-
console.error("Error sending Telegram message:", error);
26-
});
27-
}
2811

2912
// 读取以分钟为单位的运行时间限制
3013
const runTimeLimitMinutes = process.env.RUN_TIME_LIMIT_MINUTES || 15;
@@ -61,6 +44,23 @@ if (fs.existsSync(".env.local")) {
6144
"Using .env file to supply config environment variables, you can create a .env.local file to overwrite defaults, it doesn't upload to git"
6245
);
6346
}
47+
const token = process.env.TELEGRAM_BOT_TOKEN;
48+
const chatId = process.env.TELEGRAM_CHAT_ID;
49+
const specificUser = process.env.SPECIFIC_USER || "14790897";
50+
let bot;
51+
if (token && chatId) {
52+
bot = new TelegramBot(token);
53+
}
54+
function sendToTelegram(message) {
55+
bot
56+
.sendMessage(chatId, message)
57+
.then(() => {
58+
console.log("Telegram message sent successfully");
59+
})
60+
.catch((error) => {
61+
console.error("Error sending Telegram message:", error);
62+
});
63+
}
6464
// 从环境变量解析用户名和密码
6565
const usernames = process.env.USERNAMES.split(",");
6666
const passwords = process.env.PASSWORDS.split(",");
@@ -196,17 +196,18 @@ async function launchBrowserForUser(username, password) {
196196

197197
// 在每个新的文档加载时执行外部脚本
198198
await page.evaluateOnNewDocument((...args) => {
199-
const [scriptToEval] = args;
199+
const [specificUser, scriptToEval] = args;
200200
localStorage.setItem("specificUser", specificUser);
201+
console.log('当前点赞用户:', specificUser)
201202
eval(scriptToEval);
202-
}, externalScript);
203+
},specificUser, externalScript);//变量必须从外部显示的传入, 因为在浏览器上下文它是读取不了的
203204
// 添加一个监听器来监听每次页面加载完成的事件
204205
page.on("load", async () => {
205206
// await page.evaluate(externalScript); //因为这个是在页面加载好之后执行的,而脚本是在页面加载好时刻来判断是否要执行,由于已经加载好了,脚本就不会起作用
206207
});
207208
// 如果是Linuxdo,就导航到我的帖子,但我感觉这里写没什么用,因为外部脚本已经定义好了
208209
if (loginUrl == "https://linux.do") {
209-
await page.goto("https://linux.do/t/topic/13716/340", {
210+
await page.goto("https://linux.do/t/topic/13716/400", {
210211
waitUntil: "domcontentloaded",
211212
});
212213
} else if (loginUrl == "https://meta.appinn.net") {

0 commit comments

Comments
 (0)