From f57d5128dae5e3cffc9928589cf9c427e84d648c Mon Sep 17 00:00:00 2001 From: liuweiqing Date: Tue, 3 Sep 2024 15:42:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20env.local=E5=90=8E=E6=89=8D=E8=83=BD?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=EF=BC=8C?= =?UTF-8?q?page.evaluate=E5=8F=98=E9=87=8F=E5=BF=85=E9=A1=BB=E4=BB=8E?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E6=98=BE=E7=A4=BA=E7=9A=84=E4=BC=A0=E5=85=A5?= =?UTF-8?q?,=20=E5=9B=A0=E4=B8=BA=E5=9C=A8=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E5=AE=83=E6=98=AF=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E4=B8=8D=E4=BA=86=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bypasscf.js | 33 +++++++++++++++++---------------- bypasscf_likeUser.js | 41 +++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/bypasscf.js b/bypasscf.js index e372c28b..4f327f90 100644 --- a/bypasscf.js +++ b/bypasscf.js @@ -8,22 +8,6 @@ import { dirname, join } from "path"; import TelegramBot from "node-telegram-bot-api"; dotenv.config(); -const token = process.env.TELEGRAM_BOT_TOKEN; -const chatId = process.env.TELEGRAM_CHAT_ID; -let bot; -if (token && chatId) { - bot = new TelegramBot(token); -} -function sendToTelegram(message) { - bot - .sendMessage(chatId, message) - .then(() => { - console.log("Telegram message sent successfully"); - }) - .catch((error) => { - console.error("Error sending Telegram message:", error); - }); -} // 读取以分钟为单位的运行时间限制 const runTimeLimitMinutes = process.env.RUN_TIME_LIMIT_MINUTES || 15; @@ -60,6 +44,23 @@ if (fs.existsSync(".env.local")) { "Using .env file to supply config environment variables, you can create a .env.local file to overwrite defaults, it doesn't upload to git" ); } +const token = process.env.TELEGRAM_BOT_TOKEN; +const chatId = process.env.TELEGRAM_CHAT_ID; +let bot; +if (token && chatId) { + bot = new TelegramBot(token); +} +function sendToTelegram(message) { + bot + .sendMessage(chatId, message) + .then(() => { + console.log("Telegram message sent successfully"); + }) + .catch((error) => { + console.error("Error sending Telegram message:", error); + }); +} + // 从环境变量解析用户名和密码 const usernames = process.env.USERNAMES.split(","); const passwords = process.env.PASSWORDS.split(","); diff --git a/bypasscf_likeUser.js b/bypasscf_likeUser.js index b61669ce..6a7ffbd7 100644 --- a/bypasscf_likeUser.js +++ b/bypasscf_likeUser.js @@ -8,23 +8,6 @@ import { dirname, join } from "path"; import TelegramBot from "node-telegram-bot-api"; dotenv.config(); -const token = process.env.TELEGRAM_BOT_TOKEN; -const chatId = process.env.TELEGRAM_CHAT_ID; -const specificUser = process.env.SPECIFIC_USER || "14790897"; -let bot; -if (token && chatId) { - bot = new TelegramBot(token); -} -function sendToTelegram(message) { - bot - .sendMessage(chatId, message) - .then(() => { - console.log("Telegram message sent successfully"); - }) - .catch((error) => { - console.error("Error sending Telegram message:", error); - }); -} // 读取以分钟为单位的运行时间限制 const runTimeLimitMinutes = process.env.RUN_TIME_LIMIT_MINUTES || 15; @@ -61,6 +44,23 @@ if (fs.existsSync(".env.local")) { "Using .env file to supply config environment variables, you can create a .env.local file to overwrite defaults, it doesn't upload to git" ); } +const token = process.env.TELEGRAM_BOT_TOKEN; +const chatId = process.env.TELEGRAM_CHAT_ID; +const specificUser = process.env.SPECIFIC_USER || "14790897"; +let bot; +if (token && chatId) { + bot = new TelegramBot(token); +} +function sendToTelegram(message) { + bot + .sendMessage(chatId, message) + .then(() => { + console.log("Telegram message sent successfully"); + }) + .catch((error) => { + console.error("Error sending Telegram message:", error); + }); +} // 从环境变量解析用户名和密码 const usernames = process.env.USERNAMES.split(","); const passwords = process.env.PASSWORDS.split(","); @@ -196,17 +196,18 @@ async function launchBrowserForUser(username, password) { // 在每个新的文档加载时执行外部脚本 await page.evaluateOnNewDocument((...args) => { - const [scriptToEval] = args; + const [specificUser, scriptToEval] = args; localStorage.setItem("specificUser", specificUser); + console.log('当前点赞用户:', specificUser) eval(scriptToEval); - }, externalScript); + },specificUser, externalScript);//变量必须从外部显示的传入, 因为在浏览器上下文它是读取不了的 // 添加一个监听器来监听每次页面加载完成的事件 page.on("load", async () => { // await page.evaluate(externalScript); //因为这个是在页面加载好之后执行的,而脚本是在页面加载好时刻来判断是否要执行,由于已经加载好了,脚本就不会起作用 }); // 如果是Linuxdo,就导航到我的帖子,但我感觉这里写没什么用,因为外部脚本已经定义好了 if (loginUrl == "https://linux.do") { - await page.goto("https://linux.do/t/topic/13716/340", { + await page.goto("https://linux.do/t/topic/13716/400", { waitUntil: "domcontentloaded", }); } else if (loginUrl == "https://meta.appinn.net") {