Skip to content

Commit 95b6e66

Browse files
committed
更新[网易云音乐]签到脚本: 优化代码及系统通知
1 parent 0fef620 commit 95b6e66

3 files changed

Lines changed: 68 additions & 60 deletions

File tree

‎neteasemusic/quanx/README.md‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
music.163.com
88

99
[rewrite_local]
10-
^https:\/\/music\.163\.com\/m\/ url script-response-body neteasemusic.cookie.js
10+
^https:\/\/music\.163\.com\/m\/?.? url script-response-body neteasemusic.cookie.js
1111

1212
[task_local]
1313
1 0 * * * neteasemusic.js
@@ -19,7 +19,7 @@ music.163.com
1919
2. 把`neteasemusic.cookie.js`和`neteasemusic.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
2020
3. 再把两条脚本分别放到`[rewrite_local]`和`[task_local]`
2121
4. 浏览器访问并登录: https://music.163.com/m/login
22-
5. 打开浏览器访问: http://music.163.com (注意了, 是 http, 没有 s)
22+
5. 打开浏览器访问: https://music.163.com/m/
2323
6. `QuanX`提示: `Cookie [网易云音乐] 写入成功`
2424
7. 最后就可以把`[rewrite_local]`的脚本注释掉了
2525

@@ -33,7 +33,6 @@ music.163.com
3333

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

3837
2. 写入 Cookie 成功, 但签到不成功
3938

@@ -70,12 +69,6 @@ music.163.com
7069
*/60 * * * * xxx.js # 每60分执行一次
7170
```
7271

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

8174
[@NobyDa](https://github.com/NobyDa)
Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
/**
2-
*
3-
* [MITM]
4-
* music.163.com
5-
*
6-
* [rewrite_local]
7-
* ^https:\/\/music\.163\.com\/m\/ url script-response-body neteasemusic.cookie.js
8-
*
9-
* [task_local]
10-
* 1 0 0 * * neteasemusic.js
11-
*
12-
*/
13-
14-
const cookieName = "网易云音乐";
15-
const cookieKey = "chavy_cookie_neteasemusic";
16-
const cookieVal = $request.headers["Cookie"];
1+
const cookieName = '网易云音乐'
2+
const cookieKey = 'chavy_cookie_neteasemusic'
3+
const cookieVal = $request.headers['Cookie']
174

185
if (cookieVal) {
19-
let cookie = $prefs.setValueForKey(cookieVal, cookieKey);
6+
let cookie = $prefs.setValueForKey(cookieVal, cookieKey)
207
if (cookie) {
21-
let msg = `Cookie [${cookieName}] 写入成功!`;
22-
$notify(msg, "", "详见日志");
8+
let msg = `Cookie [${cookieName}] 写入成功!`
9+
$notify(msg, '', '详见日志')
10+
console.log(msg)
11+
console.log(cookieVal)
2312
}
2413
}
2514

26-
$done({});
15+
$done({})

‎neteasemusic/quanx/neteasemusic.js‎

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,79 @@
1-
/**
2-
*
3-
* [MITM]
4-
* music.163.com
5-
*
6-
* [rewrite_local]
7-
* ^https:\/\/music\.163\.com\/m\/ url script-response-body neteasemusic.cookie.js
8-
*
9-
* [task_local]
10-
* 1 0 0 * * neteasemusic.js
11-
*
12-
*/
1+
const cookieName = '网易云音乐'
2+
const cookieKey = 'chavy_cookie_neteasemusic'
3+
const cookieVal = $prefs.valueForKey(cookieKey)
134

14-
function sign() {
15-
const cookieName = '网易云音乐'
16-
const cookieKey = 'chavy_cookie_neteasemusic'
17-
const cookieVal = $prefs.valueForKey(cookieKey)
18-
19-
const pc = `http://music.163.com/api/point/dailyTask?type=1`
20-
const mobile = `http://music.163.com/api/point/dailyTask?type=0`
5+
const pc = `http://music.163.com/api/point/dailyTask?type=1`
6+
const mobile = `http://music.163.com/api/point/dailyTask?type=0`
217

8+
function sign() {
229
let url = {
2310
url: null,
2411
headers: {
2512
Cookie: cookieVal
2613
}
2714
}
15+
16+
let signinfo = {}
17+
2818
url.url = pc
2919
$task.fetch(url).then((response) => {
30-
log('网易云音乐(PC端)', response.body)
20+
let data = response.body
21+
let result = JSON.parse(data)
22+
signinfo.pc = {
23+
title: `网易云音乐(PC)`,
24+
success: result.code == 200 || result.code == -2 ? true : false,
25+
skiped: result.code == -2 ? true : false,
26+
resultCode: result.code,
27+
resultMsg: result.msg
28+
}
29+
console.log(`开始签到: ${signinfo.pc.title}, 编码: ${result.code}, 原因: ${result.msg}`)
3130
})
3231

3332
url.url = mobile
3433
$task.fetch(url).then((response) => {
35-
log('网易云音乐(移动端)', response.body)
34+
let data = response.body
35+
let result = JSON.parse(data)
36+
signinfo.app = {
37+
title: `网易云音乐(APP)`,
38+
success: result.code == 200 || result.code == -2 ? true : false,
39+
skiped: result.code == -2 ? true : false,
40+
resultCode: result.code,
41+
resultMsg: result.msg
42+
}
43+
console.log(`开始签到: ${signinfo.app.title}, 编码: ${result.code}, 原因: ${result.msg}`)
3644
})
45+
check(signinfo)
3746
}
3847

39-
function log(title, data) {
40-
let result = JSON.parse(data)
41-
if (result.code == 200) {
42-
console.log(`签到成功: ${title}`)
43-
$notify('签到成功', title, '')
44-
} else if (result.code == -2) {
45-
console.log(`签到跳过: ${title}, 编码: ${result.code}, 原因: ${result.msg}`)
46-
$notify('签到跳过', title, `原因: ${result.msg}`)
48+
function check(signinfo, checkms = 0) {
49+
if (signinfo.pc && signinfo.app) {
50+
log(signinfo)
51+
$done({})
52+
} else {
53+
if (checkms > 5000) {
54+
$done({})
55+
} else {
56+
setTimeout(() => check(signinfo, checkms + 100), 100)
57+
}
58+
}
59+
}
60+
61+
function log(signinfo) {
62+
let title = `签到结果: ${cookieName}`
63+
let subTitle = ``
64+
let detail = `今日共签: ${signinfo.signedCnt}, 本次成功: ${signinfo.successCnt}, 失败: ${signinfo.failedCnt}, 跳过: ${signinfo.skipedCnt}`
65+
66+
if (signinfo.pc.success && signinfo.app.success) {
67+
subTitle = `全部签到成功`
68+
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}`
69+
} else if (!signinfo.pc.success && !signinfo.app.success) {
70+
subTitle = `全部签到失败`
71+
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}, 详见日志!`
4772
} else {
48-
console.log(`签到失败: ${title}, 编码: ${result.code}, 原因: ${result.msg}`)
49-
$notify('签到失败', title, `原因: ${result.msg}`)
73+
subTitle = ``
74+
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}, 详见日志!`
5075
}
76+
$notify(title, subTitle, detail)
5177
}
5278

5379
sign()

0 commit comments

Comments
 (0)