Advertisement
Guest User

Untitled

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