File tree Expand file tree Collapse file tree 4 files changed +19
-333
lines changed Expand file tree Collapse file tree 4 files changed +19
-333
lines changed Original file line number Diff line number Diff line change
1
+ .env
1
2
node_modules /
Original file line number Diff line number Diff line change 198
198
) ;
199
199
}
200
200
}
201
+ // 从localStorage获取当前的点击计数,如果不存在则初始化为0
202
+ let clickCounter = parseInt ( localStorage . getItem ( "clickCounter" ) || "0" , 10 ) ;
201
203
function autoLike ( ) {
202
204
// 寻找所有的discourse-reactions-reaction-button
203
205
const buttons = document . querySelectorAll (
206
208
207
209
// 逐个点击找到的按钮
208
210
buttons . forEach ( ( button , index ) => {
209
- if ( button . title !== "点赞此帖子" ) {
211
+ if ( button . title !== "点赞此帖子" || clickCounter >= 50 ) {
210
212
return ;
211
213
}
212
214
215
217
// 模拟点击
216
218
button . click ( ) ;
217
219
console . log ( `Clicked button ${ index + 1 } ` ) ;
220
+ clickCounter ++ ; // 更新点击计数器
221
+ // 将新的点击计数存储到localStorage
222
+ localStorage . setItem ( "clickCounter" , clickCounter . toString ( ) ) ;
223
+ // 如果点击次数达到50次,则设置点赞变量为false
224
+ if ( clickCounter === 50 ) {
225
+ console . log ( "Reached 50 likes, setting the like variable to false." ) ;
226
+ localStorage . setItem ( "autoLikeEnabled" , "false" ) ; // 使用localStorage存储点赞变量状态
227
+ }
218
228
} , index * 1000 ) ; // 这里的1000毫秒是两次点击之间的间隔,可以根据需要调整
219
229
} ) ;
220
230
}
Original file line number Diff line number Diff line change @@ -34,15 +34,17 @@ const puppeteer = require("puppeteer");
34
34
await delayClick ( 500 ) ; // 延迟500毫秒
35
35
// 清空输入框并输入用户名
36
36
await page . click ( "#login-account-name" , { clickCount : 3 } ) ;
37
- await page . type ( "#login-account-name" , "hahaha2" , { delay : 100 } ) ; // 输入时在每个按键之间添加额外的延迟
37
+ await page . type ( "#login-account-name" , process . env . USERNAME , { delay : 100 } ) ; // 输入时在每个按键之间添加额外的延迟
38
38
39
39
// 等待密码输入框加载
40
40
await page . waitForSelector ( "#login-account-password" ) ;
41
41
// 模拟人类在输入用户名后的短暂停顿
42
42
await delayClick ( 500 ) ;
43
43
// 清空输入框并输入密码
44
44
await page . click ( "#login-account-password" , { clickCount : 3 } ) ;
45
- await page . type ( "#login-account-password" , "BfdSGt}F4!5pLHt" , { delay : 100 } ) ;
45
+ await page . type ( "#login-account-password" , process . env . PASSWORD , {
46
+ delay : 100 ,
47
+ } ) ;
46
48
47
49
// 模拟人类在输入完成后思考的短暂停顿
48
50
await delayClick ( 1000 ) ;
@@ -52,6 +54,9 @@ const puppeteer = require("puppeteer");
52
54
await delayClick ( 500 ) ; // 模拟在点击登录按钮前的短暂停顿
53
55
await page . click ( "#login-button" ) ;
54
56
57
+ //真正执行阅读脚本
58
+ await page . goto ( "https://linux.do/t/topic/13716/100" ) ;
59
+
55
60
// 读取外部脚本文件的内容
56
61
const externalScriptPath = path . join ( __dirname , "external.js" ) ;
57
62
const externalScript = fs . readFileSync ( externalScriptPath , "utf8" ) ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments