-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchaotikum_status.js
64 lines (52 loc) · 1.59 KB
/
chaotikum_status.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
const params = args.widgetParameter ? args.widgetParameter.split(",") : [];
const isDarkTheme = params?.[0] === 'dark';
const padding = 2;
const widget = new ListWidget();
if (isDarkTheme) {
widget.backgroundColor = new Color('#1C1C1E');;
}
widget.setPadding(padding, padding, padding, padding);
widget.url = 'https://status.chaotikum.org/';
const headerText = widget.addText("Nobreakspace Status");
headerText.font = Font.mediumSystemFont(16);
headerText.centerAlignText()
widget.addText("")
if (isDarkTheme) {
headerText.textColor = new Color('#FFFFFF');
}
async function getData(){
const url = 'https://status.nobreakspace.org/spaceapi.json'
const r = new Request( url )
const body = await r.loadJSON()
return body
}
async function createWidget() {
let response = await getData()
log(response)
let isOpen = response.state.open
let status = ""
let statusColor = Color.black()
if(isOpen){
status = "Offen"
statusColor = Color.green()
} else {
status = "Geschlossen"
statusColor = Color.red()
}
const name = widget.addText( status )
name.font = Font.mediumSystemFont(16);
name.textColor = statusColor
name.centerAlignText()
let unixTimestamp = response.state.lastchange
let lastChangeDate = new Date(unixTimestamp * 1000)
const date = widget.addDate(lastChangeDate)
date.applyTimerStyle()
date.font = Font.mediumSystemFont(16);
date.centerAlignText()
if (isDarkTheme) {
date.textColor = new Color('#FFFFFF');
}
}
await createWidget()
Script.setWidget( widget )
Script.complete()