|
1 | | -const chavy = init() |
2 | | -const cookieName = 'WPS' |
3 | | -const KEY_signhomeurl = 'chavy_signhomeurl_wps' |
4 | | -const KEY_signhomeheader = 'chavy_signhomeheader_wps' |
5 | | -const KEY_signwxurl = 'chavy_signwxurl_wps' |
6 | | -const KEY_signwxheader = 'chavy_signwxheader_wps' |
| 1 | +const $ = new Env('WPS') |
7 | 2 |
|
8 | | -if ($request && $request.method != 'OPTIONS' && $request.url.match(/act_list/)) { |
9 | | - const VAL_signhomeurl = $request.url |
10 | | - const VAL_signhomeheader = JSON.stringify($request.headers) |
11 | | - if (VAL_signhomeurl) chavy.setdata(VAL_signhomeurl, KEY_signhomeurl) |
12 | | - if (VAL_signhomeheader) chavy.setdata(VAL_signhomeheader, KEY_signhomeheader) |
13 | | - chavy.msg(cookieName, `获取Cookie: 成功 (APP)`, ``) |
14 | | -} else if ($request && $request.method != 'OPTIONS' && $request.url.match(/sign_up/)) { |
15 | | - const VAL_signwxurl = $request.url |
16 | | - const VAL_signwxheader = JSON.stringify($request.headers) |
17 | | - if (VAL_signwxurl) chavy.setdata(VAL_signwxurl, KEY_signwxurl) |
18 | | - if (VAL_signwxheader) chavy.setdata(VAL_signwxheader, KEY_signwxheader) |
19 | | - chavy.msg(cookieName, `获取Cookie: 成功 (小程序)`, ``) |
20 | | -} |
| 3 | +!(async () => { |
| 4 | + $.log('', `🔔 ${$.name}, 获取会话: 开始!`, '') |
| 5 | + const VAL_url = $request.url |
| 6 | + const VAL_headers = JSON.stringify($request.headers) |
| 7 | + $.log('', `❌ ${$.name}`, `url: ${$request.url}`, `headers: ${JSON.stringify($request.headers)}`, '') |
21 | 8 |
|
22 | | -function init() { |
23 | | - isSurge = () => { |
24 | | - return undefined === this.$httpClient ? false : true |
25 | | - } |
26 | | - isQuanX = () => { |
27 | | - return undefined === this.$task ? false : true |
28 | | - } |
29 | | - getdata = (key) => { |
30 | | - if (isSurge()) return $persistentStore.read(key) |
31 | | - if (isQuanX()) return $prefs.valueForKey(key) |
32 | | - } |
33 | | - setdata = (key, val) => { |
34 | | - if (isSurge()) return $persistentStore.write(key, val) |
35 | | - if (isQuanX()) return $prefs.setValueForKey(key, val) |
36 | | - } |
37 | | - msg = (title, subtitle, body) => { |
38 | | - if (isSurge()) $notification.post(title, subtitle, body) |
39 | | - if (isQuanX()) $notify(title, subtitle, body) |
40 | | - } |
41 | | - log = (message) => console.log(message) |
42 | | - get = (url, cb) => { |
43 | | - if (isSurge()) { |
44 | | - $httpClient.get(url, cb) |
45 | | - } |
46 | | - if (isQuanX()) { |
47 | | - url.method = 'GET' |
48 | | - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
49 | | - } |
50 | | - } |
51 | | - post = (url, cb) => { |
52 | | - if (isSurge()) { |
53 | | - $httpClient.post(url, cb) |
54 | | - } |
55 | | - if (isQuanX()) { |
56 | | - url.method = 'POST' |
57 | | - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
58 | | - } |
59 | | - } |
60 | | - done = (value = {}) => { |
61 | | - $done(value) |
62 | | - } |
63 | | - return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
64 | | -} |
65 | | -chavy.done() |
| 9 | + if (VAL_url && VAL_headers && /act_list/.test(VAL_url)) { |
| 10 | + $.setdata(VAL_url, 'chavy_signhomeurl_wps') |
| 11 | + $.setdata(VAL_headers, 'chavy_signhomeheader_wps') |
| 12 | + $.subt = '获取会话: 成功 (签到)!' |
| 13 | + } else if (VAL_url && VAL_headers && /clock_in/.test(VAL_url)) { |
| 14 | + $.setdata(VAL_url, 'chavy_signwxurl_wps') |
| 15 | + $.setdata(VAL_headers, 'chavy_signwxheader_wps') |
| 16 | + $.subt = '获取会话: 成功 (打卡)!' |
| 17 | + } |
| 18 | +})() |
| 19 | + .catch((e) => { |
| 20 | + $.subt = '获取会话: 失败!' |
| 21 | + $.desc = `原因: ${e}` |
| 22 | + $.log(`❌ ${$.name}, 获取会话: 失败! 原因: ${e}!`) |
| 23 | + }) |
| 24 | + .finally(() => { |
| 25 | + $.msg($.name, $.subt, $.desc), $.log('', `🔔 ${$.name}, 获取会话: 结束!`, ''), $.done() |
| 26 | + }) |
| 27 | + |
| 28 | +// prettier-ignore |
| 29 | +function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i);const e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t&&e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n"))}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s&&(s.body=e,s.statusCode=s.status),i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))} |
0 commit comments