Последняя активность 1732917987

sf-jury-duty-widget.js Исходник
1// Variables used by Scriptable.
2// These must be at the very top of the file. Do not edit.
3// icon-color: deep-blue; icon-glyph: theater-masks;
4
5// Your reporting group number:
6const GROUP_NUMBER = 69
7
8const PAGE =
9 'https://www.sfsuperiorcourt.org/divisions/jury-services/jury-reporting'
10const REPORTING = 'REPORTING'
11const STANDBY = 'STANDBY'
12const SAFE = 'safe'
13const WANTED = 'wanted'
14const UNCLEAR = 'unclear'
15
16const RE_HTML = /<\/?[\w\s]*>|<.+[\W]>/g
17const RE_RESULTS = new RegExp(
18 `GROUPS.*?:\s?\nGroups.*${GROUP_NUMBER}.*?\n`,
19 'g'
20)
21
22const COLOR_RED = new Color('#FF9580')
23const COLOR_GREEN = new Color('#8AFF80')
24
25const fetchPage = async (URL) => {
26 const req = new Request(URL)
27 const str = await req.loadString()
28 return str.replace(RE_HTML, '')
29}
30
31const getResults = async () => {
32 const data = await fetchPage(PAGE)
33 const results = data.match(RE_RESULTS)
34 return results ? results.join('') : ''
35}
36
37const getType = (results) => {
38 if (results.indexOf(STANDBY) !== -1) {
39 return SAFE
40 }
41 if (results.indexOf(REPORTING) !== -1) {
42 return WANTED
43 }
44 return UNCLEAR
45}
46
47const makeWidget = async () => {
48 const results = await getResults()
49 const type = getType(results)
50
51 const widget = new ListWidget()
52 const gradient = new LinearGradient()
53 gradient.colors = [new Color('#000'), new Color('#000')]
54 gradient.locations = [0, 1]
55 widget.backgroundGradient = gradient
56
57 const textStack = widget.addStack()
58 textStack.layoutVertically()
59 textStack.centerAlignContent()
60
61 const textPrefix = textStack.addText('You are')
62 textPrefix.font = Font.semiboldRoundedSystemFont(16)
63 textPrefix.textColor = new Color('#F8F8F2')
64 textPrefix.leftAlignText()
65
66 const textTitle = textStack.addText(type)
67 textTitle.font = Font.boldRoundedSystemFont(32)
68 textTitle.textColor = type === WANTED ? COLOR_RED : COLOR_GREEN
69 textTitle.leftAlignText()
70
71 widget.url = PAGE
72
73 return widget
74}
75
76const widget = await makeWidget()
77if (config.runsInWidget) {
78 Script.setWidget(widget)
79 Script.complete()
80} else {
81 widget.presentSmall()
82}
83