MCPcopy Create free account
hub / github.com/chavyleung/scripts / init

Function init

fandeng/fandeng.cookie.js:21–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19}
20
21function 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}
64senku.done()

Callers 1

fandeng.cookie.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected