Skip to content

Commit 3111835

Browse files
committed
添加[V2EX]签到脚本
1 parent 5ef9e7c commit 3111835

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

‎v2ex/README.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# V2EX
2+
3+
## 配置
4+
5+
```properties
6+
[MITM]
7+
*.v2ex.com
8+
9+
[Script]
10+
http-request ^https:\/\/www\.v2ex\.com\/mission\/daily script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.cookie.js
11+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.js
12+
```
13+
14+
## 说明
15+
16+
1. 先把`*.v2ex.com`加到`[MITM]`
17+
2. 再把两条远程脚本放到`[Script]`
18+
3. 浏览器访问并登录: https://www.v2ex.com
19+
4. 打开浏览器访问: https://www.v2ex.com/mission/daily (注意了, 是 http, 没有 s)
20+
5. `Surge`提示: `Cookie [V2EX] 写入成功`
21+
6. 最后就可以把第 1 条脚本注释掉了
22+
23+
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
24+
25+
> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次.
26+
27+
## 常见问题
28+
29+
1. 无法写入 Cookie
30+
31+
- 检查 Surge 系统通知权限放开了没
32+
- 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴)
33+
- 注意: 写入 Cookie 的网址是`http`开头的(不是 https, 没有 s, 没有 s, 没有要)
34+
35+
2. 写入 Cookie 成功, 但签到不成功
36+
37+
- 看看是不是在登录前就写入 Cookie 了
38+
- 如果是,请确保在登录成功后,再尝试写入 Cookie
39+
40+
## 感谢
41+
42+
[@NobyDa](https://github.com/NobyDa)
43+
44+
[@lhie1](https://github.com/lhie1)
45+
46+
[@ConnersHua](https://github.com/ConnersHua)

‎v2ex/v2ex.cookie.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
*
3+
* [MITM]
4+
* *.v2ex.com
5+
*
6+
* [Script]
7+
* http-request ^http:\/\/www\.v2ex\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.cookie.js
8+
* cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.js
9+
*
10+
*/
11+
12+
const cookieName = 'V2EX'
13+
const cookieKey = 'chavy_cookie_v2ex'
14+
const cookieVal = $request.headers['Cookie']
15+
16+
if (cookieVal) {
17+
let cookie = $persistentStore.write(cookieVal, cookieKey)
18+
if (cookie) {
19+
let msg = `Cookie [${cookieName}] 写入成功!`
20+
$notification.post(msg, '', '详见日志')
21+
console.log(msg)
22+
console.log(cookieVal)
23+
}
24+
}
25+
26+
$done({})

‎v2ex/v2ex.js‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
*
3+
* [MITM]
4+
* *.v2ex.com
5+
*
6+
* [Script]
7+
* http-request ^https://www.v2ex.com/ script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.cookie.js
8+
* cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.js
9+
*
10+
*/
11+
12+
const cookieName = 'V2EX'
13+
const cookieKey = 'chavy_cookie_v2ex'
14+
const cookieVal = $persistentStore.read(cookieKey)
15+
16+
function sign() {
17+
let url = {
18+
url: `https://www.v2ex.com/mission/daily`,
19+
headers: {
20+
Cookie: cookieVal
21+
}
22+
}
23+
24+
$httpClient.get(url, (error, response, data) => {
25+
if (data.indexOf('每日登录奖励已领取')) {
26+
console.log(`签到跳过: ${cookieName}, 原因: 今天已经签过了`)
27+
$notification.post('签到跳过', cookieName, `原因: 今天已经签过了`)
28+
} else {
29+
let regex = /<input[^>]*\/mission\/daily\/redeem\?once=(\d+)[^>]*>/g
30+
for (const code of data.matchAll(regex)) {
31+
signMission(code[1])
32+
}
33+
}
34+
})
35+
$done({})
36+
}
37+
38+
function signMission(code) {
39+
let url = {
40+
url: `https://www.v2ex.com/mission/daily/redeem?once=${code}`,
41+
headers: { Cookie: cookieVal }
42+
}
43+
$httpClient.get(url, (error, response, data) => {
44+
if (data.indexOf('每日登录奖励已领取') > 0) {
45+
console.log(`签到成功: ${cookieName}`)
46+
$notification.post('签到成功', cookieName, '')
47+
} else {
48+
console.log(`签到失败: ${cookieName}, error: ${error}, response: ${response}, data: ${data}`)
49+
$notification.post('签到失败', cookieName, '详见日志')
50+
}
51+
})
52+
}
53+
54+
sign({})

0 commit comments

Comments
 (0)