Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The URL of your JSON endpoint
- const 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.feed.entry
- }
- // 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"]
- // 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("Saving Amount")
- t.textColor = Color.white()
- t.font = new Font("San-Fransisco",25)
- // Add the current balance to the widget
- t = leftStack.addText(SavingsAmount)
- let string = SavingsAmount
- 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("Saving Percent")
- t.textColor = Color.white()
- t.font = new Font("San-Fransisco",25)
- // Add the start balance to the widget
- t = leftStack.addText(SavingsPercent)
- negative = reg.test(SavingsPercent)
- 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