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

Function init

acfun/acfun.js:55–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53}
54
55function init() {
56 isSurge = () => {
57 return undefined === this.$httpClient ? false : true
58 }
59 isQuanX = () => {
60 return undefined === this.$task ? false : true
61 }
62 getdata = (key) => {
63 if (isSurge()) return $persistentStore.read(key)
64 if (isQuanX()) return $prefs.valueForKey(key)
65 }
66 setdata = (key, val) => {
67 if (isSurge()) return $persistentStore.write(key, val)
68 if (isQuanX()) return $prefs.setValueForKey(key, val)
69 }
70 msg = (title, subtitle, body) => {
71 if (isSurge()) $notification.post(title, subtitle, body)
72 if (isQuanX()) $notify(title, subtitle, body)
73 }
74 log = (message) => console.log(message)
75 get = (url, cb) => {
76 if (isSurge()) {
77 $httpClient.get(url, cb)
78 }
79 if (isQuanX()) {
80 url.method = 'GET'
81 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
82 }
83 }
84 post = (url, cb) => {
85 if (isSurge()) {
86 $httpClient.post(url, cb)
87 }
88 if (isQuanX()) {
89 url.method = 'POST'
90 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
91 }
92 }
93 done = (value = {}) => {
94 $done(value)
95 }
96 return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
97}

Callers 1

acfun.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected