forked from chavyleung/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv2ex.js
48 lines (45 loc) · 1.46 KB
/
v2ex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const cookieName = 'V2EX'
const cookieKey = 'chavy_cookie_v2ex'
const cookieVal = $persistentStore.read(cookieKey)
function sign() {
let url = {
url: `https://www.v2ex.com/mission/daily`,
headers: {
Cookie: cookieVal
}
}
$httpClient.get(url, (error, response, data) => {
if (data.indexOf('每日登录奖励已领取') >= 0) {
let title = `${cookieName}`
let subTitle = `签到结果: 签到跳过`
let detail = `今天已经签过了`
console.log(`${title}, ${subTitle}, ${detail}`)
$notification.post(title, subTitle, detail)
} else {
signMission(data.match(/<input[^>]*\/mission\/daily\/redeem\?once=(\d+)[^>]*>/)[1])
}
})
$done({})
}
function signMission(code) {
let url = {
url: `https://www.v2ex.com/mission/daily/redeem?once=${code}`,
headers: { Cookie: cookieVal }
}
$httpClient.get(url, (error, response, data) => {
if (data.indexOf('每日登录奖励已领取') >= 0) {
let title = `${cookieName}`
let subTitle = `签到结果: 签到成功`
let detail = ``
console.log(`${title}, ${subTitle}, ${detail}`)
$notification.post(title, subTitle, detail)
} else {
let title = `${cookieName}`
let subTitle = `签到结果: 签到失败`
let detail = `详见日志`
console.log(`签到失败: ${cookieName}, error: ${error}, response: ${response}, data: ${data}`)
$notification.post(title, subTitle, detail)
}
})
}
sign({})