Skip to content

Commit 12d9ffa

Browse files
author
GideonSenku
committed
添加[樊登读书]签到脚本
1 parent ad048f6 commit 12d9ffa

File tree

3 files changed

+240
-0
lines changed

3 files changed

+240
-0
lines changed

fandeng/README.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# 樊登读书
2+
3+
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
4+
5+
> QuanX 需要: v1.0.6-build195 及以后版本 (TestFlight)
6+
7+
> 感谢 [@GideonSenku](https://github.com/GideonSenku) Commit
8+
9+
## 配置 (Surge)
10+
11+
```properties
12+
[MITM]
13+
api.dushu.io
14+
15+
[Script]
16+
http-request ^https://api\.dushu\.io/CheckIn script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.cookie.js, requires-body=true
17+
18+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.js
19+
```
20+
21+
## 配置 (QuanX)
22+
23+
```properties
24+
[MITM]
25+
api.dushu.io
26+
27+
[rewrite_local]
28+
29+
# [商店版] QuanX v1.0.6-build194 及更早版本
30+
# 不支持
31+
32+
# [TestFlight] QuanX v1.0.6-build195 及以后版本
33+
^https://api\.dushu\.io/CheckIn url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.cookie.js
34+
35+
[task_local]
36+
1 0 * * * fandeng.js
37+
```
38+
39+
## 说明
40+
41+
1. 先把`api.dushu.io`加到`[MITM]`
42+
2. 再配置重写规则:
43+
- Surge: 把两条远程脚本放到`[Script]`
44+
- QuanX: 把`fandeng.cookie.js``fandeng.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
45+
3. 打开 APP 手动签到一次: 访问下右下角 `我的` > `签到`
46+
4. 系统提示: `获取Cookie: 成功`
47+
5. 把获取 Cookie 的脚本注释掉
48+
6. 运行一次脚本, 如果提示重复签到, 那就算成功了!
49+
50+
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
51+
52+
> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次.
53+
54+
## 常见问题
55+
56+
1. 无法写入 Cookie
57+
58+
- 检查 Surge 系统通知权限放开了没
59+
- 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴)
60+
61+
2. 写入 Cookie 成功, 但签到不成功
62+
63+
- 看看是不是在登录前就写入 Cookie 了
64+
- 如果是,请确保在登录成功后,再尝试写入 Cookie
65+
66+
3. 为什么有时成功有时失败
67+
68+
- 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败)
69+
- 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学):
70+
71+
- `Surge`配置:
72+
73+
```properties
74+
# 没有什么是一顿饭解决不了的:
75+
cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次
76+
# 如果有,那就两顿:
77+
cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次
78+
# 实在不行,三顿也能接受:
79+
cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次
80+
81+
# 再粗暴点,直接:
82+
cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次
83+
```
84+
85+
- `QuanX`配置:
86+
87+
```properties
88+
[task_local]
89+
1 0 * * * xxx.js # 每天00:01执行一次
90+
2 0 * * * xxx.js # 每天00:02执行一次
91+
3 0 * * * xxx.js # 每天00:03执行一次
92+
93+
*/60 * * * * xxx.js # 每60分执行一次
94+
```
95+
96+
## 感谢
97+
98+
[@NobyDa](https://github.com/NobyDa)
99+
100+
[@lhie1](https://github.com/lhie1)
101+
102+
[@ConnersHua](https://github.com/ConnersHua)
103+
104+
[@GideonSenku](https://github.com/GideonSenku)

fandeng/fandeng.cookie.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const cookieName = '樊登读书'
2+
const signurlKey = 'senku_signurl_pandeng'
3+
const signheaderKey = 'senku_signheader_pandeng'
4+
const signbodyKey = 'senku_signbody_pandeng'
5+
const senku = init()
6+
7+
const requrl = $request.url
8+
if ($request && $request.method != 'OPTIONS') {
9+
const signurlVal = requrl
10+
const signheaderVal = JSON.stringify($request.headers)
11+
const signbodyVal = $request.body
12+
senku.log(`signurlVal:${signurlVal}`)
13+
senku.log(`signheaderVal:${signheaderVal}`)
14+
senku.log(`signbodyVal:${signbodyVal}`)
15+
if (signurlVal) senku.setdata(signurlVal, signurlKey)
16+
if (signheaderVal) senku.setdata(signheaderVal, signheaderKey)
17+
if (signbodyVal) senku.setdata(signbodyVal, signbodyKey)
18+
senku.msg(cookieName, `获取Cookie: 成功`, ``)
19+
}
20+
21+
function init() {
22+
isSurge = () => {
23+
return undefined === this.$httpClient ? false : true
24+
}
25+
isQuanX = () => {
26+
return undefined === this.$task ? false : true
27+
}
28+
getdata = (key) => {
29+
if (isSurge()) return $persistentStore.read(key)
30+
if (isQuanX()) return $prefs.valueForKey(key)
31+
}
32+
setdata = (key, val) => {
33+
if (isSurge()) return $persistentStore.write(key, val)
34+
if (isQuanX()) return $prefs.setValueForKey(key, val)
35+
}
36+
msg = (title, subtitle, body) => {
37+
if (isSurge()) $notification.post(title, subtitle, body)
38+
if (isQuanX()) $notify(title, subtitle, body)
39+
}
40+
log = (message) => console.log(message)
41+
get = (url, cb) => {
42+
if (isSurge()) {
43+
$httpClient.get(url, cb)
44+
}
45+
if (isQuanX()) {
46+
url.method = 'GET'
47+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
48+
}
49+
}
50+
post = (url, cb) => {
51+
if (isSurge()) {
52+
$httpClient.post(url, cb)
53+
}
54+
if (isQuanX()) {
55+
url.method = 'POST'
56+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
57+
}
58+
}
59+
done = (value = {}) => {
60+
$done(value)
61+
}
62+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
63+
}
64+
senku.done()

fandeng/fandeng.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const cookieName = '樊登读书'
2+
const signurlKey = 'senku_signurl_pandeng'
3+
const signheaderKey = 'senku_signheader_pandeng'
4+
const signbodyKey = 'senku_signbody_pandeng'
5+
const senku = init()
6+
const signurlVal = senku.getdata(signurlKey)
7+
const signheaderVal = senku.getdata(signheaderKey)
8+
const signBodyVal = senku.getdata(signbodyKey)
9+
10+
sign()
11+
12+
function sign() {
13+
const url = { url: signurlVal, headers: JSON.parse(signheaderVal), body: signBodyVal }
14+
senku.post(url, (error, response, data) => {
15+
senku.log(`${cookieName}, data: ${data}`)
16+
const res = JSON.parse(data)
17+
let subTitle = ``
18+
let detail = ``
19+
if (res.status == 1) {
20+
subTitle = `签到结果: 成功`
21+
} else {
22+
subTitle = `签到结果: 失败`
23+
detail = `状态: ${res.message}`
24+
}
25+
senku.msg(cookieName, subTitle, detail)
26+
senku.done()
27+
})
28+
}
29+
30+
function init() {
31+
isSurge = () => {
32+
return undefined === this.$httpClient ? false : true
33+
}
34+
isQuanX = () => {
35+
return undefined === this.$task ? false : true
36+
}
37+
getdata = (key) => {
38+
if (isSurge()) return $persistentStore.read(key)
39+
if (isQuanX()) return $prefs.valueForKey(key)
40+
}
41+
setdata = (key, val) => {
42+
if (isSurge()) return $persistentStore.write(key, val)
43+
if (isQuanX()) return $prefs.setValueForKey(key, val)
44+
}
45+
msg = (title, subtitle, body) => {
46+
if (isSurge()) $notification.post(title, subtitle, body)
47+
if (isQuanX()) $notify(title, subtitle, body)
48+
}
49+
log = (message) => console.log(message)
50+
get = (url, cb) => {
51+
if (isSurge()) {
52+
$httpClient.get(url, cb)
53+
}
54+
if (isQuanX()) {
55+
url.method = 'GET'
56+
$task.fetch(url).then((resp) => cb(null, resp, resp.body))
57+
}
58+
}
59+
post = (url, cb) => {
60+
if (isSurge()) {
61+
$httpClient.post(url, cb)
62+
}
63+
if (isQuanX()) {
64+
url.method = 'POST'
65+
$task.fetch(url).then((resp) => cb(null, resp, resp.body))
66+
}
67+
}
68+
done = (value = {}) => {
69+
$done(value)
70+
}
71+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
72+
}

0 commit comments

Comments
 (0)