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

Function init

tieba/tieba.cookie.js:20–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

tieba.cookie.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected