Guest User

Untitled

a guest
Jan 25th, 2026
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. // Variables used by Scriptable.
  2. // These must be at the very top of the file. Do not edit.
  3. // icon-color: light-gray; icon-glyph: copy;
  4.  
  5. // This is a minimal Widget script template
  6. // See Widget-HelloWorld.js for something slightly more interesting
  7.  
  8. // These are "asynchronous" functions, which is a fancy way of
  9. // saying that they can take some time, and you need to wait
  10. let myData = await loadData()
  11. let widget = await createWidget(myData)
  12.  
  13. // If the script isn't running as a Widget,
  14. // show a debugging preview of the widget,
  15. // in Scriptable itself
  16. if ( ! config.runsInWidget) {
  17. await widget.presentMedium()
  18. }
  19.  
  20. // Finalize widget for display on Home screen
  21. // This is the "real" way to present a widget
  22. Script.setWidget(widget)
  23. Script.complete()
  24. // End of script execution
  25.  
  26.  
  27. ///
  28. /// Implementation functions
  29. ///
  30.  
  31. // "Slow" data loading function
  32. async function loadData() {
  33. // This function loads essential data, e.g., via web request
  34.  
  35. const url = 'https://hourlypricing.comed.com/api?type=currenthouraverage&format=json'
  36. var req = new Request(url)
  37. var result = await req.loadJSON()
  38. // log(result[0]["price"])
  39. return result[0]["price"]
  40.  
  41. // return 'Hello world'
  42. }
  43.  
  44. // Widget creation, contents, layout, etc.
  45. // This is all the "what goes inside" the widget.
  46. async function createWidget(theMessage) {
  47.  
  48. // Create the widget object
  49. let widget = new ListWidget()
  50. widget.backgroundColor = new Color("#4a525a") // a nice gray
  51.  
  52. // Add content to the widget
  53.  
  54. // Flexible spacer above content to center it vertically
  55. widget.addSpacer()
  56.  
  57. // Add a line of text
  58. let titleTxt = widget.addText(theMessage)
  59. titleTxt.font = Font.boldSystemFont(24)
  60. titleTxt.textColor = new Color("#eeeeee") // almost white
  61.  
  62. // Flexible spacer below content to center it vertically
  63. widget.addSpacer()
  64.  
  65. // Return the fully composed widget object to the main script
  66. // The main script is responsible for actually presenting the widget
  67. return widget
  68. }
Advertisement
Add Comment
Please, Sign In to add comment