You start with a very simple widget.
const widget = new ListWidget()
const title = widget.addText('Covid-19')
Script.setWidget(widget)
await widget.presentSmall()
then start filling-in some data
const widget = new ListWidget()
const title = widget.addText('Covid-19')
const url = 'https://www.koronavirus.hr/json/?action=podaci_zadnji'
const req= new Request(url)
const data = await req.loadJSON()
// get the desired data. in this case it's the first and only item
const stats = data[0]
// get the number of cases in Croatia
const cases = stats.SlucajeviHrvatska
const casesCroatia = widget.addText(cases.toString())
Script.setWidget(widget)
await widget.presentSmall()
then some formatting and alignment
const widget = new ListWidget()
const title = widget.addText('🇭🇷 Covid-19')
title.centerAlignText()
const url = 'https://www.koronavirus.hr/json/?action=podaci_zadnji'
const req= new Request(url)
const data = await req.loadJSON()
// get the desired data. in this case it's the first and only item
const stats = data[0]
// get the number of cases in Croatia
const cases = stats.SlucajeviHrvatska
const casesStr = 'Slucajevi: ' + (new Intl.NumberFormat().format(cases))
const casesCroatia = widget.addText(casesStr)
casesCroatia.centerAlignText()
casesCroatia.font = Font.systemFont(12)
Script.setWidget(widget)
await widget.presentSmall()
and a few more bells and whistles, you can have this.
