|
1 | 1 | const cookieName = '百度贴吧' |
2 | 2 | const cookieKey = 'chavy_cookie_tieba' |
| 3 | +const chavy = init() |
3 | 4 | const cookieVal = $request.headers['Cookie'] |
4 | 5 |
|
5 | 6 | if (cookieVal.indexOf('BDUSS') > 0) { |
6 | | - let cookie = $persistentStore.write(cookieVal, cookieKey) |
| 7 | + let cookie = chavy.setdata(cookieVal, cookieKey) |
7 | 8 | if (cookie) { |
8 | | - let msg = `${cookieName}` |
9 | | - $notification.post(msg, 'Cookie写入成功', '详见日志') |
10 | | - console.log(msg) |
11 | | - console.log(cookieVal) |
| 9 | + let subTitle = '获取Cookie: 成功' |
| 10 | + chavy.msg(`${cookieName}`, subTitle, '') |
| 11 | + chavy.log(`[${cookieName}] ${subTitle}, cookie: ${cookieVal}`) |
12 | 12 | } |
13 | 13 | } else { |
14 | | - let msg = `${cookieName}` |
15 | | - let msgDetail = `获取失败: 请确保在已登录状态下获取Cookie` |
16 | | - $notification.post(msg, '', msgDetail) |
17 | | - console.log(`${msg}, ${msgDetail}`) |
18 | | - console.log(cookieVal) |
| 14 | + let subTitle = '获取Cookie: 失败' |
| 15 | + let detail = `请确保在已登录状态下获取Cookie` |
| 16 | + chavy.msg(`${cookieName}`, subTitle, detail) |
| 17 | + chavy.log(`[${cookieName}] ${subTitle}, cookie: ${cookieVal}`) |
19 | 18 | } |
20 | 19 |
|
21 | | -$done({}) |
| 20 | +function init() { |
| 21 | + isSurge = () => { |
| 22 | + return undefined === this.$httpClient ? false : true |
| 23 | + } |
| 24 | + isQuanX = () => { |
| 25 | + return undefined === this.$task ? false : true |
| 26 | + } |
| 27 | + getdata = (key) => { |
| 28 | + if (isSurge()) return $persistentStore.read(key) |
| 29 | + if (isQuanX()) return $prefs.valueForKey(key) |
| 30 | + } |
| 31 | + setdata = (key, val) => { |
| 32 | + if (isSurge()) return $persistentStore.write(key, val) |
| 33 | + if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 34 | + } |
| 35 | + msg = (title, subtitle, body) => { |
| 36 | + if (isSurge()) $notification.post(title, subtitle, body) |
| 37 | + if (isQuanX()) $notify(title, subtitle, body) |
| 38 | + } |
| 39 | + log = (message) => console.log(message) |
| 40 | + get = (url, cb) => { |
| 41 | + if (isSurge()) { |
| 42 | + $httpClient.get(url, cb) |
| 43 | + } |
| 44 | + if (isQuanX()) { |
| 45 | + url.method = 'GET' |
| 46 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 47 | + } |
| 48 | + } |
| 49 | + post = (url, cb) => { |
| 50 | + if (isSurge()) { |
| 51 | + $httpClient.post(url, cb) |
| 52 | + } |
| 53 | + if (isQuanX()) { |
| 54 | + url.method = 'POST' |
| 55 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 56 | + } |
| 57 | + } |
| 58 | + done = (value = {}) => { |
| 59 | + $done(value) |
| 60 | + } |
| 61 | + return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 62 | +} |
| 63 | + |
| 64 | +chavy.done() |
0 commit comments