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

Function init

10010/10010.js:218–268  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

216}
217
218function init() {
219 isSurge = () => {
220 return undefined === this.$httpClient ? false : true
221 }
222 isQuanX = () => {
223 return undefined === this.$task ? false : true
224 }
225 getdata = (key) => {
226 if (isSurge()) return $persistentStore.read(key)
227 if (isQuanX()) return $prefs.valueForKey(key)
228 }
229 setdata = (key, val) => {
230 if (isSurge()) return $persistentStore.write(key, val)
231 if (isQuanX()) return $prefs.setValueForKey(key, val)
232 }
233 msg = (title, subtitle, body) => {
234 if (isSurge()) $notification.post(title, subtitle, body)
235 if (isQuanX()) $notify(title, subtitle, body)
236 }
237 log = (message) => console.log(message)
238 get = (url, cb) => {
239 if (url['headers'] != undefined) {
240 delete url['headers']['Content-Length']
241 console.log(url['headers'])
242 }
243 if (isSurge()) {
244 $httpClient.get(url, cb)
245 }
246 if (isQuanX()) {
247 url.method = 'GET'
248 $task.fetch(url).then((resp) => cb(null, resp, resp.body))
249 }
250 }
251 post = (url, cb) => {
252 if (url['headers'] != undefined) {
253 delete url['headers']['Content-Length']
254 console.log(url['headers'])
255 }
256 if (isSurge()) {
257 $httpClient.post(url, cb)
258 }
259 if (isQuanX()) {
260 url.method = 'POST'
261 $task.fetch(url).then((resp) => cb(null, resp, resp.body))
262 }
263 }
264 done = (value = {}) => {
265 $done(value)
266 }
267 return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
268}

Callers 1

10010.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected