Last active
February 13, 2023 03:28
-
-
Save ZicklePop/f36a02e7e745f5ee9baea9e15713ce51 to your computer and use it in GitHub Desktop.
a scriptable widget for ios that shows your san francisco jury duty reporting status. don't forget to set your group number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: deep-blue; icon-glyph: theater-masks; | |
// Your reporting group number: | |
const GROUP_NUMBER = 69 | |
const PAGE = | |
'https://www.sfsuperiorcourt.org/divisions/jury-services/jury-reporting' | |
const REPORTING = 'REPORTING' | |
const STANDBY = 'STANDBY' | |
const SAFE = 'safe' | |
const WANTED = 'wanted' | |
const UNCLEAR = 'unclear' | |
const RE_HTML = /<\/?[\w\s]*>|<.+[\W]>/g | |
const RE_RESULTS = new RegExp( | |
`GROUPS.*?:\s?\nGroups.*${GROUP_NUMBER}.*?\n`, | |
'g' | |
) | |
const COLOR_RED = new Color('#FF9580') | |
const COLOR_GREEN = new Color('#8AFF80') | |
const fetchPage = async (URL) => { | |
const req = new Request(URL) | |
const str = await req.loadString() | |
return str.replace(RE_HTML, '') | |
} | |
const getResults = async () => { | |
const data = await fetchPage(PAGE) | |
const results = data.match(RE_RESULTS) | |
return results ? results.join('') : '' | |
} | |
const getType = (results) => { | |
if (results.indexOf(STANDBY) !== -1) { | |
return SAFE | |
} | |
if (results.indexOf(REPORTING) !== -1) { | |
return WANTED | |
} | |
return UNCLEAR | |
} | |
const makeWidget = async () => { | |
const results = await getResults() | |
const type = getType(results) | |
const widget = new ListWidget() | |
const gradient = new LinearGradient() | |
gradient.colors = [new Color('#000'), new Color('#000')] | |
gradient.locations = [0, 1] | |
widget.backgroundGradient = gradient | |
const textStack = widget.addStack() | |
textStack.layoutVertically() | |
textStack.centerAlignContent() | |
const textPrefix = textStack.addText('You are') | |
textPrefix.font = Font.semiboldRoundedSystemFont(16) | |
textPrefix.textColor = new Color('#F8F8F2') | |
textPrefix.leftAlignText() | |
const textTitle = textStack.addText(type) | |
textTitle.font = Font.boldRoundedSystemFont(32) | |
textTitle.textColor = type === WANTED ? COLOR_RED : COLOR_GREEN | |
textTitle.leftAlignText() | |
widget.url = PAGE | |
return widget | |
} | |
const widget = await makeWidget() | |
if (config.runsInWidget) { | |
Script.setWidget(widget) | |
Script.complete() | |
} else { | |
widget.presentSmall() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment