This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getWtuCookie.js
121 lines (108 loc) · 4.07 KB
/
getWtuCookie.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
/*************************
【Surge 4.2+ 脚本配置】:
成功获取畅行码Cookie后,请禁用“获取纺大畅行码Cookie”脚本
*************************
[Script]
纺大畅行码签到 = type=cron,cronexp=13 7 * * *,wake-system=1,timeout=20,script-path=https://raw.githubusercontent.com/loyio/wtuHealthCode/main/wtuCode.js
获取纺大畅行码Cookie = type=http-request,pattern=https:\/\/jk\.wtu\.edu\.cn\/health\/mobile\/health_report,requires-body=1,max-size=0,script-path=https://raw.githubusercontent.com/loyio/wtuHealthCode/main/getWtuCookie.js,script-update-interval=0
[MITM]
hostname = jk.wtu.edu.cn
*/
const loyio= init()
GetCookie()
function GetCookie() {
try {
if ($request.headers && $request.url.match(/jk\.wtu\.edu\.cn\/health\/mobile\/health_report/)) {
var ckHeaderAuth = $request.headers.Authorization
var rqBody = $request.body
loyio.msg("测试数据ckHeader: ", ckHeaderAuth)
loyio.msg("测试数据rqBody: ", rqBody)
if (ckHeader["Authorization"] && rqBody){
var CookieHeaderKey = "wtuCkHeaderAuth"
var CookieBodyKey = "wtuRqBody"
} else {
loyio.msg("写入纺大畅行码Cookie失败", "", "请查看脚本内说明, 打开企业微信获取 ‼️")
loyio.done()
return
}
if (loyio.getdata(CookieHeaderKey) || loyio.getdata(CookieBodyKey)) {
if (loyio.getdata(CookieHeaderKey) != ckHeader) {
var cookieH = loyio.setdata(CookieHeaderKey, ckHeader);
if (!cookie) {
loyio.msg("更新纺大畅行码Cookie失败 ‼️");
} else {
loyio.msg("更新纺大畅行码Cookie成功 🎉");
}
} else if(loyio.getdata(CookieBodyKey) != rqBody) {
var cookieB = loyio.setdata(CookieBodyKey, rqBody);
if (!cookie) {
loyio.msg("更新纺大畅行码位置失败 ‼️");
} else {
loyio.msg("更新纺大畅行码位置成功 🎉");
}
}else{
console.log("纺大畅行码: \n与历史Cookie相同, 跳过写入")
}
} else {
var cookieH = loyio.setdata(CookieHeaderKey, ckHeader);
var cookieB = loyio.setdata(CookieBodyKey, rqBody);
if (!cookieH || !cookieB) {
loyio.msg("首次写入纺大畅行码Cookie失败 ‼️");
} else {
loyio.msg("首次写入纺大畅行码Cookie成功 🎉");
}
}
} else {
loyio.msg("写入纺大畅行码Cookie失败", "", "请检查匹配URL或配置内脚本类型 ‼️");
}
} catch (eor) {
loyio.setdata("wtuCkHeaderAuth", "")
loyio.setdata("wtuRqBody", "")
loyio.msg("写入纺大畅行码Cookie失败", "", '已尝试清空历史Cookie, 请重试 ⚠️')
console.log(JSON.stringify(eor) + "\n" + eor + "\n" + JSON.stringify($request.headers))
}
loyio.done()
}
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 }
}