-
Notifications
You must be signed in to change notification settings - Fork 146
/
AppleRepair.js
64 lines (53 loc) · 1.49 KB
/
AppleRepair.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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: wrench;
/**
* Author: GideonSenku
* Github: https://github.com/GideonSenku
*/
const $ = importModule("Env")
const title = 'AppleRepair'
const preview = 'medium' // 预览大小 可选:small,medium,large
const spacing = 5 // 间隙大小
const repairId = 'xxxx'
const serialNumber = 'xxxxx'
const repairMetaData = await getinfo()
await render()
async function render() {
// create and show widget
if (config.runsInWidget) {
let widget = await createWidget(repairMetaData)
Script.setWidget(widget)
Script.complete()
} else {
await createWidget(repairMetaData)
}
}
async function createWidget(repairMetaData) {
const texts = {}
repairMetaData.repairDetails.forEach((detail, idx) => {
const date = $.time('MM-dd HH:mm', detail?.time)
const labelName = detail?.status
const Line = `• ${date} ${labelName}`
texts[`text${idx}`] = Line
})
texts.battery = 'true'
const opts = {
title,
texts,
preview,
spacing
}
let widget = await $.createWidget(opts)
return widget
}
async function getinfo() {
const url = {
url: `https://mysupport.apple.com/api/v1/supportaccount/getRepairStatus?repairId=${repairId}&serialNumber=${serialNumber}`,
headers: {
'Cookie': 'SA-Locale=zh_CN;'
},
}
const { data } = await $.get(url)
return data?.repairMetaData
}