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

Function init

ximalaya/ximalaya.cookie.js:12–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10}
11
12function init() {
13 isSurge = () => {
14 return undefined === this.$httpClient ? false : true
15 }
16 isQuanX = () => {
17 return undefined === this.$task ? false : true
18 }
19 getdata = (key) => {
20 if (isSurge()) return $persistentStore.read(key)
21 if (isQuanX()) return $prefs.valueForKey(key)
22 }
23 setdata = (key, val) => {
24 if (isSurge()) return $persistentStore.write(key, val)
25 if (isQuanX()) return $prefs.setValueForKey(key, val)
26 }
27 msg = (title, subtitle, body) => {
28 if (isSurge()) $notification.post(title, subtitle, body)
29 if (isQuanX()) $notify(title, subtitle, body)
30 }
31 log = (message) => console.log(message)
32 get = (url, cb) => {
33 if (isSurge()) {
34 $httpClient.get(url, cb)
35 }
36 if (isQuanX()) {
37 url.method = 'GET'
38 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
39 }
40 }
41 post = (url, cb) => {
42 if (isSurge()) {
43 $httpClient.post(url, cb)
44 }
45 if (isQuanX()) {
46 url.method = 'POST'
47 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
48 }
49 }
50 done = (value = {}) => {
51 $done(value)
52 }
53 return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
54}
55chavy.done()

Callers 1

ximalaya.cookie.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected