Skip to content

Commit 7fa1900

Browse files
committed
添加[bilibili直播]签到脚本
1 parent 968a138 commit 7fa1900

3 files changed

Lines changed: 254 additions & 0 deletions

File tree

‎bilibili/README.md‎

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

‎bilibili/bilibili.cookie.js‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const cookieName = 'bilibili'
2+
const cookieKey = 'chavy_cookie_bilibili'
3+
const chavy = init()
4+
const cookieVal = $request.headers['Cookie']
5+
if (cookieVal) {
6+
if (chavy.setdata(cookieVal, cookieKey)) {
7+
chavy.msg(`${cookieName}`, '获取Cookie: 成功', '')
8+
chavy.log(`[${cookieName}] 获取Cookie: ${cookieVal}`)
9+
}
10+
}
11+
function init() {
12+
isSurge = () => {
13+
return undefined === this.$httpClient ? false : true
14+
}
15+
isQuanX = () => {
16+
return undefined === this.$task ? false : true
17+
}
18+
getdata = (key) => {
19+
if (isSurge()) return $persistentStore.read(key)
20+
if (isQuanX()) return $prefs.valueForKey(key)
21+
}
22+
setdata = (key, val) => {
23+
if (isSurge()) return $persistentStore.write(key, val)
24+
if (isQuanX()) return $prefs.setValueForKey(key, val)
25+
}
26+
msg = (title, subtitle, body) => {
27+
if (isSurge()) $notification.post(title, subtitle, body)
28+
if (isQuanX()) $notify(title, subtitle, body)
29+
}
30+
log = (message) => console.log(message)
31+
get = (url, cb) => {
32+
if (isSurge()) {
33+
$httpClient.get(url, cb)
34+
}
35+
if (isQuanX()) {
36+
url.method = 'GET'
37+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
38+
}
39+
}
40+
post = (url, cb) => {
41+
if (isSurge()) {
42+
$httpClient.post(url, cb)
43+
}
44+
if (isQuanX()) {
45+
url.method = 'POST'
46+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
47+
}
48+
}
49+
done = (value = {}) => {
50+
$done(value)
51+
}
52+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
53+
}
54+
chavy.done()

‎bilibili/bilibili.js‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
const cookieName = 'bilibili'
2+
const cookieKey = 'chavy_cookie_bilibili'
3+
const chavy = init()
4+
const cookieVal = chavy.getdata(cookieKey)
5+
6+
sign()
7+
8+
function sign() {
9+
let url = {
10+
url: `https://api.live.bilibili.com/sign/doSign`,
11+
headers: {
12+
Cookie: cookieVal
13+
}
14+
}
15+
url.headers['Origin'] = 'api.live.bilibili.com'
16+
url.headers['Referer'] = 'http://live.bilibili.com/'
17+
url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01'
18+
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
19+
20+
chavy.get(url, (error, response, data) => {
21+
let result = JSON.parse(data)
22+
let title = `${cookieName}`
23+
// 签到成功
24+
if (result && result.code == 0) {
25+
let subTitle = `签到结果: 成功`
26+
let detail = `本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}`
27+
chavy.msg(title, subTitle, detail)
28+
}
29+
// 签到重复
30+
else if (result && result.code == 1011040) {
31+
getsigninfo()
32+
}
33+
// 签到失败
34+
else {
35+
let subTitle = `签到结果: 失败`
36+
let detail = `说明: ${result.message}`
37+
chavy.msg(title, subTitle, detail)
38+
}
39+
chavy.log(`${cookieName}, data: ${data}`)
40+
})
41+
42+
chavy.done()
43+
}
44+
function getsigninfo() {
45+
let url = {
46+
url: `https://api.live.bilibili.com/sign/GetSignInfo`,
47+
headers: {
48+
Cookie: cookieVal
49+
}
50+
}
51+
url.headers['Host'] = 'api.live.bilibili.com'
52+
url.headers['Origin'] = 'http://live.bilibili.com'
53+
url.headers['Referer'] = 'http://live.bilibili.com/'
54+
url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01'
55+
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
56+
57+
chavy.get(url, (error, response, data) => {
58+
let title = `${cookieName}`
59+
let subTitle = `签到结果: 成功 (重复签到)`
60+
let detail = ``
61+
let result = JSON.parse(data)
62+
if (result && result.code == 0) detail = `本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}`
63+
chavy.msg(title, subTitle, detail)
64+
})
65+
}
66+
function init() {
67+
isSurge = () => {
68+
return undefined === this.$httpClient ? false : true
69+
}
70+
isQuanX = () => {
71+
return undefined === this.$task ? false : true
72+
}
73+
getdata = (key) => {
74+
if (isSurge()) return $persistentStore.read(key)
75+
if (isQuanX()) return $prefs.valueForKey(key)
76+
}
77+
setdata = (key, val) => {
78+
if (isSurge()) return $persistentStore.write(key, val)
79+
if (isQuanX()) return $prefs.setValueForKey(key, val)
80+
}
81+
msg = (title, subtitle, body) => {
82+
if (isSurge()) $notification.post(title, subtitle, body)
83+
if (isQuanX()) $notify(title, subtitle, body)
84+
}
85+
log = (message) => console.log(message)
86+
get = (url, cb) => {
87+
if (isSurge()) {
88+
$httpClient.get(url, cb)
89+
}
90+
if (isQuanX()) {
91+
url.method = 'GET'
92+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
93+
}
94+
}
95+
post = (url, cb) => {
96+
if (isSurge()) {
97+
$httpClient.post(url, cb)
98+
}
99+
if (isQuanX()) {
100+
url.method = 'POST'
101+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
102+
}
103+
}
104+
done = (value = {}) => {
105+
$done(value)
106+
}
107+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
108+
}

0 commit comments

Comments
 (0)