Ostatnio aktywny 1732917987

melanie's Avatar melanie zrewidował ten Gist 1732917987. Przejdź do rewizji

1 file changed, 82 insertions

sf-jury-duty-widget.js(stworzono plik)

@@ -0,0 +1,82 @@
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:
6 + const GROUP_NUMBER = 69
7 +
8 + const PAGE =
9 + 'https://www.sfsuperiorcourt.org/divisions/jury-services/jury-reporting'
10 + const REPORTING = 'REPORTING'
11 + const STANDBY = 'STANDBY'
12 + const SAFE = 'safe'
13 + const WANTED = 'wanted'
14 + const UNCLEAR = 'unclear'
15 +
16 + const RE_HTML = /<\/?[\w\s]*>|<.+[\W]>/g
17 + const RE_RESULTS = new RegExp(
18 + `GROUPS.*?:\s?\nGroups.*${GROUP_NUMBER}.*?\n`,
19 + 'g'
20 + )
21 +
22 + const COLOR_RED = new Color('#FF9580')
23 + const COLOR_GREEN = new Color('#8AFF80')
24 +
25 + const fetchPage = async (URL) => {
26 + const req = new Request(URL)
27 + const str = await req.loadString()
28 + return str.replace(RE_HTML, '')
29 + }
30 +
31 + const getResults = async () => {
32 + const data = await fetchPage(PAGE)
33 + const results = data.match(RE_RESULTS)
34 + return results ? results.join('') : ''
35 + }
36 +
37 + const 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 +
47 + const 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 +
76 + const widget = await makeWidget()
77 + if (config.runsInWidget) {
78 + Script.setWidget(widget)
79 + Script.complete()
80 + } else {
81 + widget.presentSmall()
82 + }
Nowsze Starsze