Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. // The URL of your JSON endpoint
  2. const endpoint = ""
  3.  
  4. //Refresh Widget
  5. const refreshInterval=15
  6.  
  7. // Function that performs the request to the JSON endpoint
  8. async function loadItems() {
  9. let at = endpoint
  10. let req = new Request(at)
  11. let corpo = await req.loadJSON()
  12. // We return just the cells
  13. return corpo.feed.entry
  14. }
  15. // Request the spreadsheet data
  16. let json = await loadItems()
  17.  
  18. // Obtaining the content of the exact cell we are looking for
  19. StartBalance = json[4].content["$t"]
  20. CurrentBalance = json[5].content["$t"]
  21. SavingsPercent = json[6].content["$t"]
  22. SavingsAmount = json[7].content["$t"]
  23.  
  24. // Create the widget
  25. let w = new ListWidget()
  26. let fm = FileManager.iCloud();
  27. let path = fm.documentsDirectory() + "/hsbcbg.png";
  28. await fm.downloadFileFromiCloud(path)
  29. w.backgroundImage = fm.readImage(path);
  30. mainStack = w.addStack()
  31. leftStack = mainStack.addStack()
  32. mainStack.addSpacer()
  33. mainStack.layoutHorizontally()
  34. leftStack.layoutVertically()
  35.  
  36. leftStack.addSpacer(6)
  37.  
  38. // Add the current balance title to the widget
  39. t = leftStack.addText("Saving Amount")
  40. t.textColor = Color.white()
  41. t.font = new Font("San-Fransisco",25)
  42.  
  43. // Add the current balance to the widget
  44. t = leftStack.addText(SavingsAmount)
  45. let string = SavingsAmount
  46. let reg = /\-/
  47. let negative = reg.test(string)
  48. if (negative){
  49. t.textColor = new Color("#ff0000")
  50. }else{
  51. t.textColor = new Color("#4CD964")
  52. }
  53. t.font = new Font("San-Fransisco",20)
  54. //t.textColor = new Color("#4CD964")
  55. //t.font = new Font("San-Fransisco",20)
  56.  
  57. leftStack.addSpacer(12)
  58.  
  59. // Add the start balance title to the widget
  60. t = leftStack.addText("Saving Percent")
  61. t.textColor = Color.white()
  62. t.font = new Font("San-Fransisco",25)
  63.  
  64. // Add the start balance to the widget
  65. t = leftStack.addText(SavingsPercent)
  66. negative = reg.test(SavingsPercent)
  67. if (negative){
  68. t.textColor = new Color("#ff0000")
  69. }else{
  70. t.textColor = new Color("#4CD964")
  71. }
  72. t.font = new Font("San-Fransisco",20)
  73. //t.textColor = new Color("#4CD964")
  74. //t.font = new Font("San-Fransisco",20)
  75.  
  76. w.addSpacer(5)
  77.  
  78. w.presentMedium()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement