Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Variables used by Scriptable.
- // These must be at the very top of the file. Do not edit.
- // icon-color: light-gray; icon-glyph: copy;
- // This is a minimal Widget script template
- // See Widget-HelloWorld.js for something slightly more interesting
- // These are "asynchronous" functions, which is a fancy way of
- // saying that they can take some time, and you need to wait
- let myData = await loadData()
- let widget = await createWidget(myData)
- // If the script isn't running as a Widget,
- // show a debugging preview of the widget,
- // in Scriptable itself
- if ( ! config.runsInWidget) {
- await widget.presentMedium()
- }
- // Finalize widget for display on Home screen
- // This is the "real" way to present a widget
- Script.setWidget(widget)
- Script.complete()
- // End of script execution
- ///
- /// Implementation functions
- ///
- // "Slow" data loading function
- async function loadData() {
- // This function loads essential data, e.g., via web request
- const url = 'https://hourlypricing.comed.com/api?type=currenthouraverage&format=json'
- var req = new Request(url)
- var result = await req.loadJSON()
- // log(result[0]["price"])
- return result[0]["price"]
- // return 'Hello world'
- }
- // Widget creation, contents, layout, etc.
- // This is all the "what goes inside" the widget.
- async function createWidget(theMessage) {
- // Create the widget object
- let widget = new ListWidget()
- widget.backgroundColor = new Color("#4a525a") // a nice gray
- // Add content to the widget
- // Flexible spacer above content to center it vertically
- widget.addSpacer()
- // Add a line of text
- let titleTxt = widget.addText(theMessage)
- titleTxt.font = Font.boldSystemFont(24)
- titleTxt.textColor = new Color("#eeeeee") // almost white
- // Flexible spacer below content to center it vertically
- widget.addSpacer()
- // Return the fully composed widget object to the main script
- // The main script is responsible for actually presenting the widget
- return widget
- }
Advertisement
Add Comment
Please, Sign In to add comment