-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBible.js
60 lines (53 loc) · 1.67 KB
/
Bible.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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: bible;
async function getVerse() {
let url = "https://www.biblegateway.com/votd/get/?format=json&version=esvuk"
let req = new Request(url)
let res = await req.loadJSON()
let ref = res.votd.reference
let ver = res.votd.text
ver = ver.replace(/(“)/g, '“')
ver = ver.replace(/(”)/g, '”')
ver = ver.replace(/(—)/g, '—')
ver = ver.replace(/(R(?:1[6-7]|2[0-1]);)/g, '')
ver = ver.replace(/\[.*\]\s*/g, '')
return await [ver, ref]
}
function createWidget(ver, ref) {
let widget = new ListWidget()
widget.setPadding(16, 16, 16, 8)
let fgColor = Color.white()
let startColor = new Color("#4982D3")
let endColor = new Color("#6E5DF7")
let gradient = new LinearGradient()
gradient.colors = [startColor, endColor]
gradient.locations = [0.0, 1]
widget.backgroundGradient = gradient
let verText = widget.addText(ver)
verText.textColor = fgColor
verText.font = Font.mediumRoundedSystemFont(24)
verText.minimumScaleFactor = 0.25
widget.addSpacer()
let refText = widget.addText(ref)
refText.textColor = fgColor
refText.font = Font.boldRoundedSystemFont(12)
refText.textOpacity = 0.5
refText.centerAlignText()
refText.minimumScaleFactor = 0.5
refText.lineLimit = 1
return widget
}
let [ver, ref] = await getVerse()
if (config.runsInWidget) {
let widget = createWidget(ver, ref)
Script.setWidget(widget)
}
if (config.runsInApp) {
ref = ref.replace(/\ /g, '+')
ref = ref.replace(/-.*/, '')
ref = "bible://" + ref
let callback = new CallbackURL(ref)
callback.open()
}
Script.complete()