-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathopenWebIf.js
More file actions
96 lines (81 loc) · 3.15 KB
/
openWebIf.js
File metadata and controls
96 lines (81 loc) · 3.15 KB
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
// Version 1.0.0
// Check www.scriptables.net for more widgets
// Use www.scriptdu.de to keep the widget up-to-date
let schema = 'http'
let openWebIfUser = 'root'
let openWebIfPassword = 'YOUR-PASSWORD'
let openWebIfUrl = 'YOUR.IP/api'
let currentChannel = await loadCurrentChannel()
let widget = await createWidget(currentChannel)
Script.setWidget(widget)
Script.complete()
async function loadCurrentChannel() {
let url = schema + "://" + openWebIfUser + ":" + openWebIfPassword + "@" + openWebIfUrl + "/getcurrent"
let req = new Request(url)
req.allowInsecureRequest = true
try {
let json = await req.loadJSON()
return json
} catch(e) {
return 'Keine Verbindung zum Server'
}
}
function getTime(timestamp) {
let ts = new Date(timestamp * 1000)
return ts.toLocaleTimeString("de-DE", {timeZone: 'Europe/Berlin', hour: '2-digit', minute:'2-digit'})
}
async function createWidget(channel) {
let widget = new ListWidget()
widget.setPadding(5, 0, 0, 5)
// set gradient background
let startColor = new Color("#000")
let endColor = new Color("#111")
let gradient = new LinearGradient()
gradient.colors = [startColor, endColor]
gradient.locations = [0, 1]
widget.backgroundColor = new Color("#000")
widget.backgroundGradient = gradient
if (typeof channel !== "object") {
let nowText = widget.addText(channel)
nowText.font = Font.boldSystemFont(12)
nowText.textColor = Color.white()
nowText.centerAlignText()
nowText.textOpacity = 0.8
} else {
let nowChannelText = widget.addText(channel.now.sname)
nowChannelText.font = Font.boldSystemFont(12)
nowChannelText.textColor = Color.white()
nowChannelText.centerAlignText()
nowChannelText.textOpacity = 0.8
widget.addSpacer(5)
let nowText = widget.addText("JETZT")
nowText.font = Font.boldSystemFont(12)
nowText.textColor = Color.white()
nowText.centerAlignText()
nowText.textOpacity = 0.8
let nowTimeTxt = widget.addText(getTime(channel.now.begin_timestamp) + " Uhr")
nowTimeTxt.font = Font.semiboldSystemFont(12)
nowTimeTxt.textColor = Color.white()
nowTimeTxt.centerAlignText()
let nowTitleTxt = widget.addText(channel.now.title)
nowTitleTxt.font = Font.semiboldSystemFont(12)
nowTitleTxt.textColor = Color.white()
nowTitleTxt.centerAlignText()
widget.addSpacer(5)
let nextText = widget.addText("NÄCHSTE")
nextText.font = Font.boldSystemFont(12)
nextText.textColor = Color.white()
nextText.centerAlignText()
nextText.textOpacity = 0.8
let nextTimeTxt = widget.addText(getTime(channel.next.begin_timestamp) + " Uhr")
nextTimeTxt.font = Font.semiboldSystemFont(12)
nextTimeTxt.textColor = Color.white()
nextTimeTxt.centerAlignText()
let nextTitleTxt = widget.addText(channel.next.title)
nextTitleTxt.font = Font.semiboldSystemFont(12)
nextTitleTxt.textColor = Color.white()
nextTitleTxt.centerAlignText()
widget.addSpacer()
}
return widget
}