Skip to content

Commit 0f55f41

Browse files
committed
添加[芒果TV]签到脚本
1 parent ce94707 commit 0f55f41

3 files changed

Lines changed: 224 additions & 0 deletions

File tree

‎mgtv/README.md‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# 芒果 TV
2+
3+
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
4+
5+
## 配置 (Surge)
6+
7+
```properties
8+
[MITM]
9+
credits.bz.mgtv.com
10+
11+
[Script]
12+
http-request ^https:\/\/credits.bz.mgtv.com\/user\/creditsTake script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mgtv/mgtv.cookie.js
13+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mgtv/mgtv.js
14+
```
15+
16+
## 配置 (QuanX)
17+
18+
```properties
19+
[MITM]
20+
credits.bz.mgtv.com
21+
22+
[rewrite_local]
23+
^https:\/\/credits.bz.mgtv.com\/user\/creditsTake url script-request-header mgtv.cookie.js
24+
25+
[task_local]
26+
1 0 * * * mgtv.js
27+
```
28+
29+
## 说明
30+
31+
1. 先把`credits.bz.mgtv.com`加到`[MITM]`
32+
2. 再配置重写规则:
33+
- Surge: 把两条远程脚本放到`[Script]`
34+
- QuanX: 把`mgtv.cookie.js`和`mgtv.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
35+
3. 打开 APP , 系统提示: `获取刷新链接: 成功`
36+
4. 然后手动签到 1 次, 系统提示: `获取Cookie: 成功`
37+
5. 最后就可以把两条脚本注释掉了
38+
6. 运行一次脚本, 如果提示重复签到, 那就算成功了!
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)

‎mgtv/mgtv.cookie.js‎

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

‎mgtv/mgtv.js‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const cookieName = '芒果TV'
2+
const signurlKey = 'chavy_signurl_mgtv'
3+
const signheaderKey = 'chavy_signheader_mgtv'
4+
const chavy = init()
5+
const signurlVal = chavy.getdata(signurlKey)
6+
const signheaderVal = chavy.getdata(signheaderKey)
7+
8+
sign()
9+
10+
function sign() {
11+
const url = { url: signurlVal, headers: JSON.parse(signheaderVal) }
12+
url.body = '{}'
13+
chavy.post(url, (error, response, data) => {
14+
chavy.log(`${cookieName}, data: ${data}`)
15+
const title = `${cookieName}`
16+
let subTitle = ''
17+
let detail = ''
18+
const result = JSON.parse(data.match(/\(([^\)]*)\)/)[1])
19+
if (result.code == 200) {
20+
subTitle = `签到结果: 成功`
21+
detail = `共签: ${result.data.curDay}天, 连签: ${result.data.curDayTotal}天, 积分: ${result.data.balance} +${result.data.credits})`
22+
} else if (result.code == 1002) {
23+
subTitle = `签到结果: 成功 (重复签到)`
24+
} else {
25+
subTitle = `签到结果: 失败`
26+
detail = `编码: ${result.code}, 说明: ${result.msg}`
27+
}
28+
chavy.msg(title, subTitle, detail)
29+
chavy.done()
30+
})
31+
}
32+
33+
function init() {
34+
isSurge = () => {
35+
return undefined === this.$httpClient ? false : true
36+
}
37+
isQuanX = () => {
38+
return undefined === this.$task ? false : true
39+
}
40+
getdata = (key) => {
41+
if (isSurge()) return $persistentStore.read(key)
42+
if (isQuanX()) return $prefs.valueForKey(key)
43+
}
44+
setdata = (key, val) => {
45+
if (isSurge()) return $persistentStore.write(key, val)
46+
if (isQuanX()) return $prefs.setValueForKey(key, val)
47+
}
48+
msg = (title, subtitle, body) => {
49+
if (isSurge()) $notification.post(title, subtitle, body)
50+
if (isQuanX()) $notify(title, subtitle, body)
51+
}
52+
log = (message) => console.log(message)
53+
get = (url, cb) => {
54+
if (isSurge()) {
55+
$httpClient.get(url, cb)
56+
}
57+
if (isQuanX()) {
58+
url.method = 'GET'
59+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
60+
}
61+
}
62+
post = (url, cb) => {
63+
if (isSurge()) {
64+
$httpClient.post(url, cb)
65+
}
66+
if (isQuanX()) {
67+
url.method = 'POST'
68+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
69+
}
70+
}
71+
done = (value = {}) => {
72+
$done(value)
73+
}
74+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
75+
}

0 commit comments

Comments
 (0)