Skip to content

Commit 7bfd5a1

Browse files
committed
更新[百度贴吧]签到脚本: Surge & QuanX脚本二合一、优化性能、通知、日志输出
1 parent 47979c5 commit 7bfd5a1

6 files changed

Lines changed: 151 additions & 239 deletions

File tree

‎tieba/README.md‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# 百度贴吧
1+
# 百度贴吧 (Surge & QuanX 二合一签到脚本)
22

3-
## 配置
3+
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
4+
5+
## 配置 (Surge)
46

57
```properties
68
[MITM]
@@ -11,13 +13,28 @@ http-request ^https?:\/\/tieba\.baidu\.com\/?.? script-path=https://raw.githubus
1113
cron "10 0 0 * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.js
1214
```
1315

16+
## 配置 (QuanX)
17+
18+
```properties
19+
[MITM]
20+
tieba.baidu.com
21+
22+
[rewrite_local]
23+
^https?:\/\/tieba\.baidu\.com\/?.? url script-response-body tieba.cookie.js
24+
25+
[task_local]
26+
1 0 * * * tieba.js
27+
```
28+
1429
## 说明
1530

16-
1. 先把`tieba.baidu.com`加到`[MITM]`
17-
2. 再把两条远程脚本放到`[Script]`
18-
3. 先在浏览器登录 `(先登录! 先登录! 先登录!)`
31+
1. 先在浏览器登录 `(先登录! 先登录! 先登录!)`
32+
2. 先把`tieba.baidu.com`加到`[MITM]`
33+
3. 再配置重写规则:
34+
- Surge: 把两条远程脚本放到`[Script]`
35+
- QuanX: 把`tieba.cookie.js`和`tieba.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
1936
4. 再用浏览器访问一下: https://tieba.baidu.com 或者 https://tieba.baidu.com/index/
20-
5. `Surge`提示: `Cookie [百度贴吧] 写入成功` (如果提示多条写入成功,忽略就好)
37+
5. 系统提示: `获取Cookie: 成功`
2138
6. 最后就可以把第 1 条脚本注释掉了
2239

2340
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.

‎tieba/quanx/README.md‎

Lines changed: 0 additions & 77 deletions
This file was deleted.

‎tieba/quanx/tieba.cookie.js‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎tieba/quanx/tieba.js‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎tieba/tieba.cookie.js‎

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,64 @@
11
const cookieName = '百度贴吧'
22
const cookieKey = 'chavy_cookie_tieba'
3+
const chavy = init()
34
const cookieVal = $request.headers['Cookie']
45

56
if (cookieVal.indexOf('BDUSS') > 0) {
6-
let cookie = $persistentStore.write(cookieVal, cookieKey)
7+
let cookie = chavy.setdata(cookieVal, cookieKey)
78
if (cookie) {
8-
let msg = `${cookieName}`
9-
$notification.post(msg, 'Cookie写入成功', '详见日志')
10-
console.log(msg)
11-
console.log(cookieVal)
9+
let subTitle = '获取Cookie: 成功'
10+
chavy.msg(`${cookieName}`, subTitle, '')
11+
chavy.log(`[${cookieName}] ${subTitle}, cookie: ${cookieVal}`)
1212
}
1313
} else {
14-
let msg = `${cookieName}`
15-
let msgDetail = `获取失败: 请确保在已登录状态下获取Cookie`
16-
$notification.post(msg, '', msgDetail)
17-
console.log(`${msg}, ${msgDetail}`)
18-
console.log(cookieVal)
14+
let subTitle = '获取Cookie: 失败'
15+
let detail = `请确保在已登录状态下获取Cookie`
16+
chavy.msg(`${cookieName}`, subTitle, detail)
17+
chavy.log(`[${cookieName}] ${subTitle}, cookie: ${cookieVal}`)
1918
}
2019

21-
$done({})
20+
function init() {
21+
isSurge = () => {
22+
return undefined === this.$httpClient ? false : true
23+
}
24+
isQuanX = () => {
25+
return undefined === this.$task ? false : true
26+
}
27+
getdata = (key) => {
28+
if (isSurge()) return $persistentStore.read(key)
29+
if (isQuanX()) return $prefs.valueForKey(key)
30+
}
31+
setdata = (key, val) => {
32+
if (isSurge()) return $persistentStore.write(key, val)
33+
if (isQuanX()) return $prefs.setValueForKey(key, val)
34+
}
35+
msg = (title, subtitle, body) => {
36+
if (isSurge()) $notification.post(title, subtitle, body)
37+
if (isQuanX()) $notify(title, subtitle, body)
38+
}
39+
log = (message) => console.log(message)
40+
get = (url, cb) => {
41+
if (isSurge()) {
42+
$httpClient.get(url, cb)
43+
}
44+
if (isQuanX()) {
45+
url.method = 'GET'
46+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
47+
}
48+
}
49+
post = (url, cb) => {
50+
if (isSurge()) {
51+
$httpClient.post(url, cb)
52+
}
53+
if (isQuanX()) {
54+
url.method = 'POST'
55+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
56+
}
57+
}
58+
done = (value = {}) => {
59+
$done(value)
60+
}
61+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
62+
}
63+
64+
chavy.done()

0 commit comments

Comments
 (0)