Advertisement
Guest User

Untitled

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