@@ -8,23 +8,6 @@ import { dirname, join } from "path";
8
8
import TelegramBot from "node-telegram-bot-api" ;
9
9
10
10
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
- }
28
11
29
12
// 读取以分钟为单位的运行时间限制
30
13
const runTimeLimitMinutes = process . env . RUN_TIME_LIMIT_MINUTES || 15 ;
@@ -61,6 +44,23 @@ if (fs.existsSync(".env.local")) {
61
44
"Using .env file to supply config environment variables, you can create a .env.local file to overwrite defaults, it doesn't upload to git"
62
45
) ;
63
46
}
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
+ }
64
64
// 从环境变量解析用户名和密码
65
65
const usernames = process . env . USERNAMES . split ( "," ) ;
66
66
const passwords = process . env . PASSWORDS . split ( "," ) ;
@@ -196,17 +196,18 @@ async function launchBrowserForUser(username, password) {
196
196
197
197
// 在每个新的文档加载时执行外部脚本
198
198
await page . evaluateOnNewDocument ( ( ...args ) => {
199
- const [ scriptToEval ] = args ;
199
+ const [ specificUser , scriptToEval ] = args ;
200
200
localStorage . setItem ( "specificUser" , specificUser ) ;
201
+ console . log ( '当前点赞用户:' , specificUser )
201
202
eval ( scriptToEval ) ;
202
- } , externalScript ) ;
203
+ } , specificUser , externalScript ) ; //变量必须从外部显示的传入, 因为在浏览器上下文它是读取不了的
203
204
// 添加一个监听器来监听每次页面加载完成的事件
204
205
page . on ( "load" , async ( ) => {
205
206
// await page.evaluate(externalScript); //因为这个是在页面加载好之后执行的,而脚本是在页面加载好时刻来判断是否要执行,由于已经加载好了,脚本就不会起作用
206
207
} ) ;
207
208
// 如果是Linuxdo,就导航到我的帖子,但我感觉这里写没什么用,因为外部脚本已经定义好了
208
209
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 " , {
210
211
waitUntil : "domcontentloaded" ,
211
212
} ) ;
212
213
} else if ( loginUrl == "https://meta.appinn.net" ) {
0 commit comments