-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelemGetCookies.js
133 lines (108 loc) · 3.8 KB
/
elemGetCookies.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
参考chavyleung和NobyDa的写法
打开elem APP,进入签到页面,提示获取用户ID成功就可以把rewrite注释掉。只需要获取一次用户ID即可。
理论上永不会过期。
//饿了么
> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
## 配置 (Surge)
```properties
[MITM]
h5.ele.me
[Script]
http-request ^https:\/\/h5\.ele\.me\/restapi\/eus\/v\d\/current_user script-path=https://raw.githubusercontent.com/nzw9314/QuantumultX/master/Script/elemGetCookies.js
cron "0 5 0 * * *" script-path=https://raw.githubusercontent.com/nzw9314/QuantumultX/master/Script/elemSign.js
```
## 配置 (QuanX)
```properties
[MITM]
h5.ele.me
[rewrite_local]
^https:\/\/h5\.ele\.me\/restapi\/eus\/v\d\/current_user url script-request-header elemGetCookies.js
[task_local]
5 0 * * * elemSign.js
```
## 说明
1. 先把h5.ele.me`加到`[MITM]`
2. 再配置重写规则:
- Surge: 把两条远程脚本放到`[Script]`
- QuanX: 把`elemGetCookies.js`和`elemSign.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关)
3. 打开 APP, 访问下`我的`>`签到领红包`(左上角)
4. 系统提示: `获取Cookie: 成功` (如果不提示获取成功, 尝试杀进程再进`个人`>`每日签到`)
5. 最后就可以把第 1 条脚本注释掉了
> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie.
> 第 2 条脚本是签到脚本, 每天`00:05:00`执行一次.
*/
const CookieName = '饿了么'
const CookieKey = 'cookie_elem'
const UserId='user_id_elem'
const matchid=/USERID=(\d+);/
const sy = init()
GetCookie();
function GetCookie() {
if ($request.headers) {
var CookieValue = $request.headers['Cookie'];
if (sy.getdata(CookieKey) != (undefined || null)) {
if (sy.getdata(CookieKey) != CookieValue) {
var cookie = sy.setdata(CookieValue, CookieKey);
if (!cookie) {
sy.msg("更新" + CookieName + "Cookie失败‼️", "", "");
} else {
sy.msg("更新" + CookieName + "Cookie成功 🎉", "", "");
}
}
} else {
var cookie = sy.setdata(CookieValue, CookieKey);
if (!cookie) {
sy.msg("首次写入" + CookieName + "Cookie失败‼️", "", "");
} else {
sy.msg("首次写入" + CookieName + "Cookie成功 🎉", "", "");
}
}
} else {
sy.msg("写入" + CookieName + "Cookie失败‼️", "", "配置错误, 无法读取请求头, ");
}
}
function init() {
isSurge = () => {
return undefined === this.$httpClient ? false : true
}
isQuanX = () => {
return undefined === this.$task ? false : true
}
getdata = (key) => {
if (isSurge()) return $persistentStore.read(key)
if (isQuanX()) return $prefs.valueForKey(key)
}
setdata = (key, val) => {
if (isSurge()) return $persistentStore.write(key, val)
if (isQuanX()) return $prefs.setValueForKey(key, val)
}
msg = (title, subtitle, body) => {
if (isSurge()) $notification.post(title, subtitle, body)
if (isQuanX()) $notify(title, subtitle, body)
}
log = (message) => console.log(message)
get = (url, cb) => {
if (isSurge()) {
$httpClient.get(url, cb)
}
if (isQuanX()) {
url.method = 'GET'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
post = (url, cb) => {
if (isSurge()) {
$httpClient.post(url, cb)
}
if (isQuanX()) {
url.method = 'POST'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
done = (value = {}) => {
$done(value)
}
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
}
sy.done()