|
| 1 | +const cookieName = '樊登读书' |
| 2 | +const signurlKey = 'senku_signurl_pandeng' |
| 3 | +const signheaderKey = 'senku_signheader_pandeng' |
| 4 | +const signbodyKey = 'senku_signbody_pandeng' |
| 5 | +const senku = init() |
| 6 | + |
| 7 | +const requrl = $request.url |
| 8 | +if ($request && $request.method != 'OPTIONS') { |
| 9 | + const signurlVal = requrl |
| 10 | + const signheaderVal = JSON.stringify($request.headers) |
| 11 | + const signbodyVal = $request.body |
| 12 | + senku.log(`signurlVal:${signurlVal}`) |
| 13 | + senku.log(`signheaderVal:${signheaderVal}`) |
| 14 | + senku.log(`signbodyVal:${signbodyVal}`) |
| 15 | + if (signurlVal) senku.setdata(signurlVal, signurlKey) |
| 16 | + if (signheaderVal) senku.setdata(signheaderVal, signheaderKey) |
| 17 | + if (signbodyVal) senku.setdata(signbodyVal, signbodyKey) |
| 18 | + senku.msg(cookieName, `获取Cookie: 成功`, ``) |
| 19 | +} |
| 20 | + |
| 21 | +function init() { |
| 22 | + isSurge = () => { |
| 23 | + return undefined === this.$httpClient ? false : true |
| 24 | + } |
| 25 | + isQuanX = () => { |
| 26 | + return undefined === this.$task ? false : true |
| 27 | + } |
| 28 | + getdata = (key) => { |
| 29 | + if (isSurge()) return $persistentStore.read(key) |
| 30 | + if (isQuanX()) return $prefs.valueForKey(key) |
| 31 | + } |
| 32 | + setdata = (key, val) => { |
| 33 | + if (isSurge()) return $persistentStore.write(key, val) |
| 34 | + if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 35 | + } |
| 36 | + msg = (title, subtitle, body) => { |
| 37 | + if (isSurge()) $notification.post(title, subtitle, body) |
| 38 | + if (isQuanX()) $notify(title, subtitle, body) |
| 39 | + } |
| 40 | + log = (message) => console.log(message) |
| 41 | + get = (url, cb) => { |
| 42 | + if (isSurge()) { |
| 43 | + $httpClient.get(url, cb) |
| 44 | + } |
| 45 | + if (isQuanX()) { |
| 46 | + url.method = 'GET' |
| 47 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 48 | + } |
| 49 | + } |
| 50 | + post = (url, cb) => { |
| 51 | + if (isSurge()) { |
| 52 | + $httpClient.post(url, cb) |
| 53 | + } |
| 54 | + if (isQuanX()) { |
| 55 | + url.method = 'POST' |
| 56 | + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 57 | + } |
| 58 | + } |
| 59 | + done = (value = {}) => { |
| 60 | + $done(value) |
| 61 | + } |
| 62 | + return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 63 | +} |
| 64 | +senku.done() |
0 commit comments