Skip to content

Commit 4ecb78f

Browse files
committed
更新[百度贴吧]签到脚本
1 parent 59878f6 commit 4ecb78f

3 files changed

Lines changed: 78 additions & 50 deletions

File tree

‎tieba/README.md‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
tieba.baidu.com
88

99
[Script]
10-
http-request ^http:\/\/tieba\.baidu\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.cookie.js
10+
http-request ^https?:\/\/tieba\.baidu\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.cookie.js
1111
cron "10 0 0 * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.js
1212
```
1313

1414
## 说明
1515

1616
1. 先把`tieba.baidu.com`加到`[MITM]`
1717
2. 再把两条远程脚本放到`[Script]`
18-
3. 先用浏览器登录: https://tieba.baidu.com
19-
4. 再用浏览器访问一下: http://tieba.baidu.com (注意了, 是 http, 没有 s)
20-
5. `Surge`提示: `Cookie [百度贴吧] 写入成功`
18+
3. 先在浏览器登录 `(先登录! 先登录! 先登录!)`
19+
4. 再用浏览器访问一下: https://tieba.baidu.com 或者 https://tieba.baidu.com/index/
20+
5. `Surge`提示: `Cookie [百度贴吧] 写入成功` (如果提示多条写入成功,忽略就好)
2121
6. 最后就可以把第 1 条脚本注释掉了
2222

2323
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
@@ -30,7 +30,6 @@ cron "10 0 0 * *" script-path=https://raw.githubusercontent.com/chavyleung/scrip
3030

3131
- 检查 Surge 系统通知权限放开了没
3232
- 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴)
33-
- 注意: 写入 Cookie 的网址是`http`开头的(不是 https, 没有 s, 没有 s, 没有要)
3433

3534
2. 写入 Cookie 成功, 但签到不成功
3635

@@ -67,12 +66,6 @@ cron "10 0 0 * *" script-path=https://raw.githubusercontent.com/chavyleung/scrip
6766
*/60 * * * * xxx.js # 每60分执行一次
6867
```
6968

70-
4. 为什么百度贴吧签到没有系统通知
71-
72-
- 百度貌似用的 GBK 编码目前无法优雅地解码,所以就算提示出来吧名也是乱码的
73-
- 我有 20 个吧不想被消息轰炸
74-
- 目前考虑提示`本次成功:3, 本次失败:4, 今天共签5`这种提示形式,但代码层面受限制,还在想办法实现
75-
7669
## 感谢
7770

7871
[@NobyDa](https://github.com/NobyDa)

‎tieba/tieba.cookie.js‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
/**
2-
*
3-
* [MITM]
4-
* tieba.baidu.com
5-
*
6-
* [Script]
7-
* http-request ^http:\/\/tieba\.baidu\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.cookie.js
8-
* cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.js
9-
*
10-
*/
11-
121
const cookieName = '百度贴吧'
132
const cookieKey = 'chavy_cookie_tieba'
143
const cookieVal = $request.headers['Cookie']
154

16-
if (cookieVal) {
5+
if (cookieVal.indexOf('BDUSS') > 0) {
176
let cookie = $persistentStore.write(cookieVal, cookieKey)
187
if (cookie) {
198
let msg = `Cookie [${cookieName}] 写入成功!`
209
$notification.post(msg, '', '详见日志')
2110
console.log(msg)
2211
console.log(cookieVal)
2312
}
13+
} else {
14+
let msg = `Cookie [${cookieName}] 获取失败!`
15+
let msgDetail = `请确保在已登录状态下获取Cookie`
16+
$notification.post(msg, '', msgDetail)
17+
console.log(`${msg}, ${msgDetail}`)
18+
console.log(cookieVal)
2419
}
2520

2621
$done({})

‎tieba/tieba.js‎

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,92 @@
1-
/**
2-
*
3-
* [MITM]
4-
* tieba.baidu.com
5-
*
6-
* [Script]
7-
* http-request ^http:\/\/tieba\.baidu\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.cookie.js
8-
* cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.js
9-
*
10-
*/
11-
121
const cookieName = '百度贴吧'
132
const cookieKey = 'chavy_cookie_tieba'
143
const cookieVal = $persistentStore.read(cookieKey)
154

165
function sign() {
176
let url = {
18-
url: `http://tieba.baidu.com/f/like/mylike`,
7+
url: `https://tieba.baidu.com/mo/q/newmoindex`,
198
headers: {
209
Cookie: cookieVal
2110
}
2211
}
2312

2413
$httpClient.post(url, (error, response, data) => {
25-
// <a href="/f?kw=surface" title="surface">surface</a>
26-
// let regex = /\/f\?kw=([^{'"}]*)/g
27-
// let regex = /\/f\?kw=([^{'"}]*).*?>([^<]*)/g
28-
let regex = /\/f\?kw=([^{'"}]*)/g
29-
for (const bar of data.matchAll(regex)) {
30-
signBar(bar)
14+
let result = JSON.parse(data)
15+
let tbs = result.data.tbs
16+
let forums = result.data.like_forum
17+
console.log(forums.length)
18+
let signinfo = {
19+
forumCnt: forums.length,
20+
signedCnt: 0,
21+
successCnt: 0,
22+
failedCnt: 0,
23+
skipedCnt: 0
24+
}
25+
26+
let singIndex = 0
27+
for (const bar of forums) {
28+
let barName = decodeURIComponent(decodeURIComponent(bar.forum_name))
29+
// 已签
30+
if (bar.is_sign == 1) {
31+
signinfo.signedCnt += 1
32+
signinfo.skipedCnt += 1
33+
console.log(`签到跳过: ${barName}, 原因: 重复签到`)
34+
}
35+
// 未签
36+
else {
37+
singIndex += 1
38+
setTimeout(
39+
() =>
40+
signBar(bar, tbs, (error, response, data) => {
41+
console.log(data)
42+
let signresult = JSON.parse(data)
43+
if (signresult.no == 0 || signresult.no == 1011) {
44+
signinfo.signedCnt += 1
45+
signinfo.successCnt += 1
46+
console.log(`签到成功: ${barName}`)
47+
} else {
48+
signinfo.failedCnt += 1
49+
console.log(`签到失败: ${bar[1]}, 编码: ${signresult.no}, 原因: ${signresult.error}`)
50+
}
51+
}),
52+
singIndex * 100
53+
)
54+
}
3155
}
56+
check(forums, signinfo)
3257
})
33-
$done({})
3458
}
3559

36-
function signBar(bar) {
60+
function signBar(bar, tbs, cb) {
3761
let url = {
38-
url: `http://tieba.baidu.com/sign/add?ie=utf-8&kw=${bar[1]}`,
62+
url: `http://tieba.baidu.com/sign/add?ie=utf-8&kw=${bar.forum_name}&tbs=${tbs}`,
3963
headers: { Cookie: cookieVal }
4064
}
65+
$httpClient.post(url, cb)
66+
}
4167

42-
$httpClient.post(url, (error, response, data) => {
43-
let result = JSON.parse(data)
44-
if (result.no == 0) {
45-
console.log(`正在签到: ${bar[1]}, 签到成功`)
68+
function check(forums, signinfo, checkms = 0) {
69+
if (signinfo.forumCnt == signinfo.signedCnt) {
70+
let title = `签到结果: ${cookieName}`
71+
let subTitle = ``
72+
let detail = `今日共签: ${signinfo.signedCnt}, 本次成功: ${signinfo.successCnt}, 本次失败: ${signinfo.failedCnt}, 本次跳过: ${signinfo.skipedCnt}`
73+
74+
// 成功数+跳过数=总数 = 全部签到完成
75+
if (signinfo.successCnt + signinfo.skipedCnt == signinfo.signedCnt) {
76+
subTitle = `全部签到完成`
4677
} else {
47-
console.log(`正在签到: ${bar[1]}, 错误编码: ${result.no}, 错误原因: ${result.error}`)
78+
subTitle = `部分签到完成`
4879
}
49-
})
80+
console.log(`${title}, ${subTitle}, ${detail}`)
81+
$notification.post(title, subTitle, detail)
82+
$done({})
83+
} else {
84+
if (checkms > 5000) {
85+
$done({})
86+
} else {
87+
setTimeout(() => check(forums, signinfo, checkms + 100), 100)
88+
}
89+
}
5090
}
5191

5292
sign()

0 commit comments

Comments
 (0)