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