-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scripts-UN.js
256 lines (231 loc) · 8.96 KB
/
Scripts-UN.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// Author: 脑瓜
// Github: https://github.com/anker1209/Scriptable
// 该组件支持两种模式,默认为圆环进度条模式,主屏幕长按小组件-->编辑小组件-->Parameter,输入1,使用文字模式
//PS:本代码属于自用修改-有BUG。
// #############设置##############
const files = FileManager.local()
const Tel = '' // 输入联通手机号码,,在两个引号之间输入
const Cookie = ''// 输入联通cookie,在两个引号之间输入
const ringStackSize = 61 // 圆环大小
const ringTextSize = 12 // 圆环中心文字大小
const creditTextSize = 20 // 话费文本大小
const textSize = 12 // 文字模式下文字大小
const databgColor = new Color("12A6E4", 0.2) // 流量环背景颜色
const datafgColor = new Color("12A6E4") // 流量环前景颜色
const voicebgColor = new Color("F86527", 0.2) // 语音环背景颜色
const voicefgColor = new Color("F86527") // 语音环前景颜色
const newBG = false //是否设置或者使用新的背景图片,若要设置背景图片,请勿将下一行值设为true
const removeBG = false //是否需要清空背景图片,如果设置过背景图片,想再使用纯色背景,需将此设置为true清除背景图片缓存
const setbgColor = false //是否设置固定纯色背景,如要设置,请在下行指定背景颜色
const bgColor = "ffffff" // 背景颜色
const widgetParam = args.widgetParameter
let data = await getData()
let zjifen = await getzhenjifen()
const title = "中国联通"
const cuIconUrl = "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-imgbed/f77d3cdc-b757-4acd-9766-a64421bf0c6d.png"
const dataSfs = SFSymbol.named("antenna.radiowaves.left.and.right")
dataSfs.applyHeavyWeight()
const dataIcon = dataSfs.image
const voiceIcon = SFSymbol.named("phone.fill").image
const scoreIcon = SFSymbol.named("tag.fill").image
const iconColor = new Color("FE8900")
const phoneData = data.data.dataList[0]
const credit = data.data.dataList[1]
const voice = data.data.dataList[2]
//let date.date.dateList[3] ="可用积分"
const score = data.data.dataList[3]
const canvSize = 178
const canvTextSize = 45
const canvas = new DrawContext()
const canvWidth = 18
const canvRadius = 80
const widget = new ListWidget()
widget.setPadding(16, 16, 16, 16) // widget边距(上,下,左,右)
// ############背景设置############
const path = files.joinPath(files.documentsDirectory(), "Chinaunicom-20210129")
if (newBG && config.runsInApp) {
const img = await Photos.fromLibrary()
widget.backgroundImage = img
files.writeImage(path, img)
} else {
if (files.fileExists(path)) {
try {
widget.backgroundImage = files.readImage(path)
log("读取图片成功")
} catch (e) {
log(e.message)
}
}
}
if (removeBG && files.fileExists(path)) {
try {
files.remove(path)
log("背景图片清理成功")
} catch (e) {
log(e.message)
}
}
if (setbgColor) {
widget.backgroundColor = new Color(bgColor)
}
// ############LOGO###############
let headerStack = widget.addStack()
headerStack.layoutVertically
headerStack.addSpacer()
let logo = headerStack.addImage(await getImg(cuIconUrl))
logo.imageSize = new Size(393 * 0.25, 118 * 0.25)
headerStack.addSpacer()
widget.addSpacer()
let creditStack = widget.addStack()
creditStack.centerAlignContent()
creditStack.addSpacer()
let creditElement = creditStack.addText(credit.number)
creditElement.font = Font.mediumRoundedSystemFont(creditTextSize)
creditStack.addSpacer()
widget.addSpacer()
// ###############################
let bodyStack = widget.addStack()
bodyStack.layoutVertically()
if (widgetParam == "1") {
await textLayout(dataIcon, phoneData.remainTitle, phoneData.number, phoneData.unit)
bodyStack.addSpacer(8)
await textLayout(voiceIcon, voice.remainTitle, voice.number, voice.unit)
bodyStack.addSpacer(8)
await textLayout(scoreIcon, score.remainTitle, zjifen, score.unit)
} else {
canvas.size = new Size(canvSize, canvSize)
canvas.opaque = false
canvas.respectScreenScale = true
const dataGap = (100 - phoneData.persent) * 3.6
const voiceGap = (100 - voice.persent) * 3.6
drawArc(dataGap, datafgColor, databgColor)
let ringStack = bodyStack.addStack()
let ringLeft = ringStack.addStack()
ringLeft.layoutVertically()
ringLeft.size = new Size(ringStackSize, ringStackSize)
ringLeft.backgroundImage = canvas.getImage()
await ringContent(ringLeft, dataIcon, datafgColor, phoneData.number, phoneData.unit)
ringStack.addSpacer()
drawArc(voiceGap, voicefgColor, voicebgColor)
let ringRight = ringStack.addStack()
ringRight.layoutVertically()
ringRight.size = new Size(ringStackSize, ringStackSize)
ringRight.backgroundImage = canvas.getImage()
await ringContent(ringRight, voiceIcon, voicefgColor, voice.number, voice.unit)
}
// ###############################
if (!config.runsInWidget) {
await widget.presentSmall()
}
Script.setWidget(widget)
Script.complete()
async function getImg(url) {
const req = new Request(url)
const img = await req.loadImage()
return img
}
function sinDeg(deg) {
return Math.sin((deg * Math.PI) / 180)
}
function cosDeg(deg) {
return Math.cos((deg * Math.PI) / 180)
}
function ringContent(widget, icon, iconColor, text, unit) {
const rowIcon = widget.addStack()
rowIcon.addSpacer()
const iconElement = rowIcon.addImage(icon)
iconElement.tintColor = iconColor
iconElement.imageSize = new Size(12, 12)
iconElement.imageOpacity = 0.7
rowIcon.addSpacer()
widget.addSpacer(1)
const rowText = widget.addStack()
rowText.addSpacer()
const textElement = rowText.addText(text)
textElement.font = Font.mediumSystemFont(ringTextSize)
rowText.addSpacer()
const rowUnit = widget.addStack()
rowUnit.addSpacer()
const unitElement = rowUnit.addText(unit)
unitElement.font = Font.boldSystemFont(8)
unitElement.textOpacity = 0.5
rowUnit.addSpacer()
}
function textLayout(icon, title, number, unit) {
const rowItem = bodyStack.addStack()
rowItem.centerAlignContent()
let iconElement = rowItem.addImage(icon)
iconElement.imageSize = new Size(textSize, textSize)
iconElement.tintColor = iconColor
rowItem.addSpacer(4)
let titleElement = rowItem.addText(title)
titleElement.font = Font.systemFont(textSize)
rowItem.addSpacer()
let numberElement = rowItem.addText(number + unit)
numberElement.font = Font.systemFont(textSize)
}
function drawArc(deg, fillColor, strokeColor, centerColor) {
let ctr = new Point(canvSize / 2, canvSize / 2),
bgx = ctr.x - canvRadius;
bgy = ctr.y - canvRadius;
bgd = 2 * canvRadius;
bgr = new Rect(bgx, bgy, bgd, bgd)
canvas.setFillColor(fillColor)
canvas.setStrokeColor(strokeColor)
canvas.setLineWidth(canvWidth)
canvas.strokeEllipse(bgr)
for (let t = 0; t < deg; t++) {
rect_x = ctr.x + canvRadius * sinDeg(t) - canvWidth / 2
rect_y = ctr.y - canvRadius * cosDeg(t) - canvWidth / 2
rect_r = new Rect(rect_x, rect_y, canvWidth, canvWidth)
canvas.fillEllipse(rect_r)
}
}
async function getData() {
const cachePath = files.joinPath(files.documentsDirectory(), "Chinaunicom-anker")
var url = 'https://m.client.10010.com/mobileService/home/queryUserInfoSeven.htm?showType=3&[email protected]&desmobiel=' + Tel;
var url1 = 'https://act.10010.com/SigninApp/signin/daySign'
var url2 = 'https://m.client.10010.com/welfare-mall-front/mobile/show/flDetail/v1/0'
try {
var req = new Request(url)
req.headers = {
'cookie': Cookie
}
console.log(req)
var data = await req.loadJSON()
console.log(data)
var req1 = new Request(url1);
req1.headers = {
'cookie': Cookie
}
var data1 = await req1.loadJSON();
if (data.signinState === '0') {
files.writeString(cachePath, JSON.stringify(data))
log("==>数据请求成功")
}
} catch (e) {
data = JSON.parse(files.readString(cachePath))
log("==>数据请求失败,使用缓存数据/" + e)
}
return data
}
async function getzhenjifen() {
//const cachePath = files.joinPath(files.documentsDirectory(), "Chinaunicom-anker")
var url = 'https://m.client.10010.com/mobileService/home/queryUserInfoSeven.htm?showType=3&[email protected]&desmobiel=' + Tel;
var url1 = 'https://act.10010.com/SigninApp/signin/daySign'
var url2 = 'https://m.client.10010.com/welfare-mall-front/mobile/show/flDetail/v1/0'
try {
var req2 = new Request(url2);
req2.headers = {
'cookie': Cookie
}
var data2 = await req2.loadJSON();
if (data2.code === '0') {
files.writeString(cachePath, JSON.stringify(data2))
log("==>目前有可兑换积分" + data2.resdata.score.availablescore)
}
} catch (e) {
log("==>数据请求失败,使用缓存数据/" + e)
}
return data2.resdata.score.availablescore
}