Skip to content

Commit 94a557d

Browse files
committed
更新[网易云音乐]签到脚本: 优化系统通知
1 parent f0b6a1a commit 94a557d

3 files changed

Lines changed: 49 additions & 44 deletions

File tree

neteasemusic/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
[Script]
10-
http-request ^http:\/\/music\.163\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.cookie.js
10+
http-request ^https?:\/\/music\.163\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.cookie.js
1111
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.js
1212
```
1313

@@ -16,7 +16,7 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr
1616
1. 先把`music.163.com`加到`[MITM]`
1717
2. 再把两条远程脚本放到`[Script]`
1818
3. 浏览器访问并登录: https://music.163.com/m/login
19-
4. 打开浏览器访问: http://music.163.com (注意了, 是 http, 没有 s)
19+
4. 登录成功后再用浏览器访问一下: https://music.163.com/
2020
5. `Surge`提示: `Cookie [网易云音乐] 写入成功`
2121
6. 最后就可以把第 1 条脚本注释掉了
2222

@@ -30,7 +30,6 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr
3030

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

3534
2. 写入 Cookie 成功, 但签到不成功
3635

@@ -67,12 +66,6 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr
6766
*/60 * * * * xxx.js # 每60分执行一次
6867
```
6968

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

7871
[@NobyDa](https://github.com/NobyDa)

neteasemusic/neteasemusic.cookie.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
/**
2-
*
3-
* [MITM]
4-
* music.163.com
5-
*
6-
* [Script]
7-
* http-request ^http:\/\/music\.163\.com script-path=scripts/neteasemusic/neteasemusic.cookie.js
8-
* cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.js
9-
*
10-
*/
11-
121
const cookieName = '网易云音乐'
132
const cookieKey = 'chavy_cookie_neteasemusic'
143
const cookieVal = $request.headers['Cookie']

neteasemusic/neteasemusic.js

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
/**
2-
*
3-
* [MITM]
4-
* music.163.com
5-
*
6-
* [Script]
7-
* http-request ^http:\/\/music\.163\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.cookie.js
8-
* cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.js
9-
*
10-
*/
11-
121
const cookieName = '网易云音乐'
132
const cookieKey = 'chavy_cookie_neteasemusic'
143
const cookieVal = $persistentStore.read(cookieKey)
@@ -24,31 +13,65 @@ function sign() {
2413
}
2514
}
2615

16+
let signinfo = {}
17+
2718
url.url = pc
2819
$httpClient.post(url, (error, response, data) => {
29-
log('网易云音乐(PC端)', data)
20+
let result = JSON.parse(data)
21+
signinfo.pc = {
22+
title: `网易云音乐(PC)`,
23+
success: result.code == 200 || result.code == -2 ? true : false,
24+
skiped: result.code == -2 ? true : false,
25+
resultCode: result.code,
26+
resultMsg: result.msg
27+
}
28+
console.log(`开始签到: ${signinfo.pc.title}, 编码: ${result.code}, 原因: ${result.msg}`)
3029
})
3130

3231
url.url = mobile
3332
$httpClient.post(url, (error, response, data) => {
34-
log('网易云音乐(移动端)', data)
33+
let result = JSON.parse(data)
34+
signinfo.app = {
35+
title: `网易云音乐(APP)`,
36+
success: result.code == 200 || result.code == -2 ? true : false,
37+
skiped: result.code == -2 ? true : false,
38+
resultCode: result.code,
39+
resultMsg: result.msg
40+
}
41+
console.log(`开始签到: ${signinfo.app.title}, 编码: ${result.code}, 原因: ${result.msg}`)
3542
})
43+
check(signinfo)
44+
}
3645

37-
$done({})
46+
function check(signinfo, checkms = 0) {
47+
if (signinfo.pc && signinfo.app) {
48+
log(signinfo)
49+
$done({})
50+
} else {
51+
if (checkms > 5000) {
52+
$done({})
53+
} else {
54+
setTimeout(() => check(signinfo, checkms + 100), 100)
55+
}
56+
}
3857
}
3958

40-
function log(title, data) {
41-
let result = JSON.parse(data)
42-
if (result.code == 200) {
43-
console.log(`签到成功: ${title}`)
44-
$notification.post('签到成功', title, '')
45-
} else if (result.code == -2) {
46-
console.log(`签到跳过: ${title}, 编码: ${result.code}, 原因: ${result.msg}`)
47-
$notification.post('签到跳过', title, `原因: ${result.msg}`)
59+
function log(signinfo) {
60+
let title = `签到结果: ${cookieName}`
61+
let subTitle = ``
62+
let detail = `今日共签: ${signinfo.signedCnt}, 本次成功: ${signinfo.successCnt}, 失败: ${signinfo.failedCnt}, 跳过: ${signinfo.skipedCnt}`
63+
64+
if (signinfo.pc.success && signinfo.app.success) {
65+
subTitle = `全部签到成功`
66+
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}`
67+
} else if (!signinfo.pc.success && !signinfo.app.success) {
68+
subTitle = `全部签到失败`
69+
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}, 详见日志!`
4870
} else {
49-
console.log(`签到失败: ${title}, 编码: ${result.code}, 原因: ${result.msg}`)
50-
$notification.post('签到失败', title, `原因: ${result.msg}`)
71+
subTitle = ``
72+
detail = `PC: ${signinfo.pc.success ? '成功' : '失败'}, APP: ${signinfo.app.success ? '成功' : '失败'}, 详见日志!`
5173
}
74+
$notification.post(title, subTitle, detail)
5275
}
5376

5477
sign()

0 commit comments

Comments
 (0)