-
Notifications
You must be signed in to change notification settings - Fork 55
/
快递100.js
184 lines (173 loc) · 6.04 KB
/
快递100.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* 快递100 - 查询快递动态小脚本
* Powered by Pin Or JSbox
*
* @author AbleCats <[email protected]>
* @public https://t.me/Flow_Script
* @version 20180119B2
*/
var storied = $cache.get("storied") ? $cache.get("storied") : []
function Api(num) {
$ui.loading(true)
num = typeof (num) == "object" ? num[0] : num
saveOrder(num)
$http.get({
url: "https://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=" + num,
handler: function (resp) {
var data = resp.data
var comCode = data.auto[0].comCode
$http.get({
url: "https://www.kuaidi100.com/query?type=" + comCode + "&postid=" + num,
handler: function (resp) {
var data = resp.data
if (data.status == 200) cleardata(data.data)
else {
$ui.loading(false)
if (comCode == "shunfeng") $delay(timer(), function () { $ui.alert("emmm...\n快递100的顺丰接口出现问题\n自行用支付宝查询吧~") })
else $delay(timer(), function () { $ui.alert("emmm...\n没有从快递100找到数据\n请过几个小时后再查询吧~") })
}
}
})
}
})
}
function timer() {
if ($app.env == $env.today) return 0.5;
else return 0;
}
function datainfo(data) {
var info = "\n"
data = data.split(/[,,]/)
if (data) {
for (const key in data) {
info = info + "- " + data[key]
if (key != data.length - 1) info = info + "\n\n"
}
}
return info
}
function cleardata(object) {
let NILArray = []
for (const key in object) {
let data = object[key]
NILArray.push({
time: data.time,
text: data.context
})
}
$ui.loading(false)
initMessage(NILArray)
}
function makeItems(object) {
let temp = []
for (const key in object) {
t = object[key]
text = t.text.split(/[,,]/)
temp.push(t.time + " " + text[0])
}
return temp
}
function saveOrder(num) {
let length = storied.length
if (length) {
for (const key in storied) {
if (storied[key] == num) break;
else {
if (key == length - 1) {
storied.unshift(num)
$cache.set("storied", storied)
}
}
}
} else {
storied.unshift(num)
$cache.set("storied", storied)
}
}
function initMessage(data) {
let news = data[0];
$delay(timer(), function () {
$ui.alert({
title: "最新动态\n" + news.time,
message: datainfo(news.text),
actions: [{
title: "退出",
handler: function () {
$app.close()
}
}, {
title: "详细",
handler: function () {
$delay(timer(), function () {
$ui.menu({
items: makeItems(data),
handler: function (title, idx) {
let news = data[idx]
$delay(timer(), function () {
$ui.alert({
title: "当前动态\n" + news.time,
message: datainfo(news.text),
})
})
}
})
})
}
}
]
})
})
}
function Initialize() {
var num = $clipboard.text
var pattern = /[0-9]{10,14}/;
if (pattern.test(num)) Api(num.match(pattern))
else {
if (storied.length)
$ui.alert({
title: "emmm...\n貌似剪贴板没有快递单号哦~\n",
message: "是否查看历史查询单号?\n",
actions: [{
title: "否",
handler: function () {
$app.close()
}
}, {
title: "是",
handler: function () {
$delay(timer(), function () {
$ui.menu({
items: storied,
handler: function (title, idx) {
$delay(timer(), function () {
$ui.alert({
title: "单号:" + title,
message: "\n选择将要进行的操作\n",
actions: [{
title: "删除历史",
handler: function () {
for (const key in storied) {
if (storied[key] == title) {
storied.splice(key, 1)
$cache.set("storied", storied)
}
}
}
}, {
title: "查看动态",
handler: function () {
Api(title)
}
},]
})
})
}
})
})
}
}]
})
else $ui.alert("抱歉,没有找到任何单号~")
}
}
Initialize()