Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The URL of your JSON endpoint
- const endpoint =“"
- console.log(endpoint)
- // The URL of your JSON endpoint
- //Refresh Widget
- const refreshInterval=15
- // Function that performs the request to the JSON endpoint
- async function loadItems() {
- let at = endpoint
- let req = new Request(at)
- let corpo = await req.loadJSON()
- // We return just the cells
- return corpo
- }
- // Request the spreadsheet data
- let json = await loadItems()
- // Obtaining the content of the exact cell we are looking for
- //StartBalance = json[4].content["$t"]
- //CurrentBalance = json[5].content["$t"]
- //SavingsPercent = json[6].content["$t"]
- //SavingsAmount = json[7].content["$t"]
- StartBalance = json.values[4]
- CurrentBalance = json.values[5]
- SavingsPercent = json.values[6]
- SavingsAmount = json.values[7]
- // Create the widget
- let w = new ListWidget()
- let fm = FileManager.iCloud();
- let path = fm.documentsDirectory() + "/hsbcbg.png";
- await fm.downloadFileFromiCloud(path)
- w.backgroundImage = fm.readImage(path);
- mainStack = w.addStack()
- leftStack = mainStack.addStack()
- mainStack.addSpacer()
- mainStack.layoutHorizontally()
- leftStack.layoutVertically()
- leftStack.addSpacer(6)
- // Add the current balance title to the widget
- t = leftStack.addText("Current Balance")
- t.textColor = Color.white()
- t.font = new Font("San-Fransisco",25)
- // Add the current balance to the widget
- t = leftStack.addText(CurrentBalance)
- let string = CurrentBalance
- let reg = /\-/
- let negative = reg.test(string)
- if (negative){
- t.textColor = new Color("#ff0000")
- }else{
- t.textColor = new Color("#4CD964")
- }
- t.font = new Font("San-Fransisco",20)
- //t.textColor = new Color("#4CD964")
- //t.font = new Font("San-Fransisco",20)
- leftStack.addSpacer(12)
- // Add the start balance title to the widget
- t = leftStack.addText("Start Balance")
- t.textColor = Color.white()
- t.font = new Font("San-Fransisco",25)
- // Add the start balance to the widget
- t = leftStack.addText(StartBalance)
- negative = reg.test(StartBalance)
- if (negative){
- t.textColor = new Color("#ff0000")
- }else{
- t.textColor = new Color("#4CD964")
- }
- t.font = new Font("San-Fransisco",20)
- //t.textColor = new Color("#4CD964")
- //t.font = new Font("San-Fransisco",20)
- w.addSpacer(5)
- w.presentMedium()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement