|
1 |
| -const cookieName = 'APK.TW' |
2 |
| -const cookieKey = 'chavy_cookie_apktw' |
3 |
| -const chavy = init() |
4 |
| -const cookieVal = chavy.getdata(cookieKey) |
| 1 | +const $ = new Env('ApkTw') |
| 2 | +$.VAL_login = $.getdata('chavy_cookie_apktw') |
5 | 3 |
|
6 |
| -sign() |
| 4 | +!(async () => { |
| 5 | + $.log('', `🔔 ${$.name}, 开始!`, '') |
| 6 | + await login() |
| 7 | + await getHash() |
| 8 | + await sign() |
| 9 | + await showmsg() |
| 10 | +})() |
| 11 | + .catch((e) => { |
| 12 | + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') |
| 13 | + }) |
| 14 | + .finally(() => { |
| 15 | + $.msg($.name, $.subt, ''), $.log('', `🔔 ${$.name}, 结束!`, ''), $.done() |
| 16 | + }) |
7 | 17 |
|
8 |
| -function sign() { |
9 |
| - let url = { url: `https://apk.tw/`, headers: { Cookie: cookieVal } } |
10 |
| - url.headers['Host'] = 'apk.tw' |
11 |
| - url.headers['Referer'] = 'https://apk.tw/forum.php' |
12 |
| - url.headers['Accept'] = '*/*' |
13 |
| - url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' |
14 |
| - chavy.get(url, (error, response, data) => { |
15 |
| - signbbs(data.match(/\/source\/plugin\/dsu_amupper\/images\/wb\.gif/), data) |
| 18 | +// 登录 |
| 19 | +function login() { |
| 20 | + const url = JSON.parse($.VAL_login) |
| 21 | + return new Promise((resove) => $.post(url, (error, response, data) => resove())) |
| 22 | +} |
| 23 | + |
| 24 | +function getHash() { |
| 25 | + return new Promise((resove) => { |
| 26 | + const url = { url: 'https://apk.tw/', headers: {} } |
| 27 | + url.headers['Host'] = 'apk.tw' |
| 28 | + url.headers['Referer'] = 'https://apk.tw/forum.php' |
| 29 | + url.headers['Accept'] = '*/*' |
| 30 | + url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' |
| 31 | + $.get(url, (error, response, data) => { |
| 32 | + try { |
| 33 | + if (error) throw new Error(error) |
| 34 | + if (/\/source\/plugin\/dsu_amupper\/images\/wb\.gif/.test(data)) { |
| 35 | + $.isSigned = true |
| 36 | + $.isSignSuc = true |
| 37 | + } else { |
| 38 | + $.isSigned = false |
| 39 | + const [hash] = /plugin.php\?id=dsu_amupper:pper([^('|")]*)/.exec(data) |
| 40 | + if (hash) { |
| 41 | + $.hash = hash |
| 42 | + } else { |
| 43 | + $.isSignSuc = false |
| 44 | + } |
| 45 | + } |
| 46 | + } catch (e) { |
| 47 | + $.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, '') |
| 48 | + } finally { |
| 49 | + resove() |
| 50 | + } |
| 51 | + }) |
16 | 52 | })
|
17 |
| - chavy.done() |
18 | 53 | }
|
19 | 54 |
|
20 |
| -function signbbs(signedmatch, homedata) { |
21 |
| - const title = `${cookieName}` |
22 |
| - let subTitle = `` |
23 |
| - let detail = `` |
24 |
| - if (signedmatch) { |
25 |
| - subTitle = `签到结果: 成功 (重复签到)` |
26 |
| - chavy.msg(title, subTitle, detail) |
27 |
| - } else { |
28 |
| - const signmatch = homedata.match(/plugin.php\?id=dsu_amupper:pper([^\']*)/) |
29 |
| - if (signmatch) { |
30 |
| - let url = { url: `https://apk.tw/${signmatch[0]}&inajax=1&ajaxtarget=my_amupper`, headers: { Cookie: cookieVal } } |
31 |
| - url.headers['Host'] = 'apk.tw' |
32 |
| - url.headers['Referer'] = 'https://apk.tw/forum.php' |
33 |
| - url.headers['Accept'] = '*/*' |
34 |
| - url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' |
35 |
| - chavy.get(url, (error, response, data) => { |
36 |
| - chavy.log(`${cookieName}, data: ${data}`) |
37 |
| - if (data.match(/\/source\/plugin\/dsu_amupper\/images\/wb\.gif/)) { |
38 |
| - subTitle = `签到结果: 成功` |
| 55 | +function sign() { |
| 56 | + if ($.isSigned && !$.hash) return |
| 57 | + return new Promise((resove) => { |
| 58 | + const url = { url: `https://apk.tw/${$.hash}&inajax=1&ajaxtarget=my_amupper`, headers: {} } |
| 59 | + $.log(`❕ ${url.url}!`) |
| 60 | + url.headers['Host'] = 'apk.tw' |
| 61 | + url.headers['Referer'] = 'https://apk.tw/forum.php' |
| 62 | + url.headers['Accept'] = '*/*' |
| 63 | + url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' |
| 64 | + $.get(url, (error, response, data) => { |
| 65 | + try { |
| 66 | + if (error) throw new Error(error) |
| 67 | + if (/\/source\/plugin\/dsu_amupper\/images\/wb\.gif/.test(data)) { |
| 68 | + $.isSignSuc = true |
39 | 69 | } else {
|
40 |
| - subTitle = `签到结果: 失败 (未知)` |
| 70 | + $.isSignSuc = false |
41 | 71 | }
|
42 |
| - chavy.msg(title, subTitle, detail) |
43 |
| - }) |
44 |
| - } else { |
45 |
| - subTitle = `签到结果: 失败 (未知)` |
46 |
| - chavy.log(`${cookieName}, homedata: ${homedata}`) |
47 |
| - chavy.msg(title, subTitle, detail) |
48 |
| - } |
49 |
| - } |
| 72 | + } catch (e) { |
| 73 | + $.isSignSuc = false |
| 74 | + $.log(`❗️ ${$.name}, 执行失败!`, ` error = ${error || e}`, `response = ${JSON.stringify(response)}`, '') |
| 75 | + } finally { |
| 76 | + resove() |
| 77 | + } |
| 78 | + }) |
| 79 | + }) |
50 | 80 | }
|
51 |
| -function init() { |
52 |
| - isSurge = () => { |
53 |
| - return undefined === this.$httpClient ? false : true |
54 |
| - } |
55 |
| - isQuanX = () => { |
56 |
| - return undefined === this.$task ? false : true |
57 |
| - } |
58 |
| - getdata = (key) => { |
59 |
| - if (isSurge()) return $persistentStore.read(key) |
60 |
| - if (isQuanX()) return $prefs.valueForKey(key) |
61 |
| - } |
62 |
| - setdata = (key, val) => { |
63 |
| - if (isSurge()) return $persistentStore.write(key, val) |
64 |
| - if (isQuanX()) return $prefs.setValueForKey(key, val) |
65 |
| - } |
66 |
| - msg = (title, subtitle, body) => { |
67 |
| - if (isSurge()) $notification.post(title, subtitle, body) |
68 |
| - if (isQuanX()) $notify(title, subtitle, body) |
69 |
| - } |
70 |
| - log = (message) => console.log(message) |
71 |
| - get = (url, cb) => { |
72 |
| - if (isSurge()) { |
73 |
| - $httpClient.get(url, cb) |
74 |
| - } |
75 |
| - if (isQuanX()) { |
76 |
| - url.method = 'GET' |
77 |
| - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
78 |
| - } |
79 |
| - } |
80 |
| - post = (url, cb) => { |
81 |
| - if (isSurge()) { |
82 |
| - $httpClient.post(url, cb) |
83 |
| - } |
84 |
| - if (isQuanX()) { |
85 |
| - url.method = 'POST' |
86 |
| - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 81 | + |
| 82 | +function showmsg() { |
| 83 | + return new Promise((resove) => { |
| 84 | + if ($.isSigned) { |
| 85 | + $.subt = '签到: 重复' |
| 86 | + } else if (!$.isSigned && $.isSignSuc) { |
| 87 | + $.subt = '签到: 成功' |
| 88 | + } else { |
| 89 | + $.subt = '签到: 失败' |
87 | 90 | }
|
88 |
| - } |
89 |
| - done = (value = {}) => { |
90 |
| - $done(value) |
91 |
| - } |
92 |
| - return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 91 | + resove() |
| 92 | + }) |
93 | 93 | }
|
| 94 | + |
| 95 | +// prettier-ignore |
| 96 | +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