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

Function init

suning/suning.cookie.js:60–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

suning.cookie.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected