forked from chavyleung/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzaker.js
140 lines (135 loc) · 4.17 KB
/
zaker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var appName = 'ZAKER新闻'
var zaker = init()
var URL = zaker.getdata("UrlZK")
var KEY = zaker.getdata("CookieZK")
let isGetCookie = typeof $request !== 'undefined'
if (isGetCookie) {
getcookie()
} else {
sign()
}
function getcookie() {
var url = $request.url;
if (url) {
var UrlKeyZK = "UrlZK";
var UrlValueZK = url;
if (zaker.getdata(UrlKeyZK) != (undefined || null)) {
if (zaker.getdata(UrlKeyZK) != UrlValueZK) {
var url = zaker.setdata(UrlValueZK, UrlKeyZK);
if (!url) {
zaker.msg("更新" + appName + "Url失败‼️", "", "");
} else {
zaker.msg("更新" + appName + "Url成功🎉", "", "");
}
} else {
zaker.msg(appName + "Url未变化❗️", "", "");
}
} else {
var url = zaker.setdata(UrlValueZK, UrlKeyZK);
if (!url) {
zaker.msg("首次写入" + appName + "Url失败‼️", "", "");
} else {
zaker.msg("首次写入" + appName + "Url成功🎉", "", "");
}
}
} else {
zaker.msg("写入" + appName + "Url失败‼️", "", "配置错误, 无法读取URL, ");
}
if ($request.headers) {
var CookieKeyZK = "CookieZK";
var CookieValueZK = JSON.stringify($request.headers);
if (zaker.getdata(CookieKeyZK) != (undefined || null)) {
if (zaker.getdata(CookieKeyZK) != CookieValueZK) {
var cookie = zaker.setdata(CookieValueZK, CookieKeyZK);
if (!cookie) {
zaker.msg("更新" + appName + "Cookie失败‼️", "", "");
} else {
zaker.msg("更新" + appName + "Cookie成功🎉", "", "");
}
} else {
zaker.msg(appName + "Cookie未变化❗️", "", "");
}
} else {
var cookie = zaker.setdata(CookieValueZK, CookieKeyZK);
if (!cookie) {
zaker.msg("首次写入" + appName + "Cookie失败‼️", "", "");
} else {
zaker.msg("首次写入" + appName + "Cookie成功🎉", "", "");
}
}
} else {
zaker.msg("写入" + appName + "Cookie失败‼️", "", "配置错误, 无法读取请求头, ");
}
zaker.done()
}
function sign() {
const url = { url: URL, headers: JSON.parse(KEY) }
zaker.get(url, (error, response, data) => {
zaker.log(`${appName}, data: ${data}`)
const title = `${appName}`
let subTitle = ''
let detail = ''
const result = JSON.parse(data)
if (result.stat == 1) {
subTitle = `签到结果: 成功`
detail = `签到奖励: ${result.data.tips}, 总签到天数: ${result.data.total_day_count}天`
} else {
subTitle = `签到结果: 未知`
detail = `说明: ${result.msg}`
}
zaker.msg(title, subTitle, detail)
zaker.done()
})
}
function init() {
isSurge = () => {
return undefined === this.$httpClient ? false : true
}
isQuanX = () => {
return undefined === this.$task ? false : true
}
getdata = (key) => {
if (isSurge()) return $persistentStore.read(key)
if (isQuanX()) return $prefs.valueForKey(key)
}
setdata = (key, val) => {
if (isSurge()) return $persistentStore.write(key, val)
if (isQuanX()) return $prefs.setValueForKey(key, val)
}
msg = (title, subtitle, body) => {
if (isSurge()) $notification.post(title, subtitle, body)
if (isQuanX()) $notify(title, subtitle, body)
}
log = (message) => console.log(message)
get = (url, cb) => {
if (isSurge()) {
$httpClient.get(url, cb)
}
if (isQuanX()) {
url.method = 'GET'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
post = (url, cb) => {
if (isSurge()) {
$httpClient.post(url, cb)
}
if (isQuanX()) {
url.method = 'POST'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
put = (url, cb) => {
if (isSurge()) {
$httpClient.put(url, cb)
}
if (isQuanX()) {
url.method = 'PUT'
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
}
}
done = (value = {}) => {
$done(value)
}
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, put, done }
}