Skip to content

Instantly share code, notes, and snippets.

@Casperbart
Created August 20, 2020 16:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Casperbart/d8850fcdb1d7549502ce68f65854f997 to your computer and use it in GitHub Desktop.
Save Casperbart/d8850fcdb1d7549502ce68f65854f997 to your computer and use it in GitHub Desktop.
Cantina widget script for Scriptable
let widget = new ListWidget()
widget.setPadding(16, 16, 0, 16)
// Set title
let titleText = widget.addText("Dagens menu👩‍🍳")
titleText.textColor = Color.white()
titleText.applyHeadlineTextStyling()
// Set gradient background
let startColor = new Color("ff7b1c")
let endColor = new Color("fe9e0b")
let gradient = new LinearGradient()
gradient.colors = [startColor, endColor]
gradient.locations = [0.0, 1]
widget.backgroundGradient = gradient
await loadMenu()
await loadImage()
// widget.presentSmall()
widget.presentMedium()
Script.setWidget(widget)
async function loadMenu() {
let url = "https://api"
let req = new Request(url)
let menu = await req.loadJSON()
console.log(menu)
if(menu != null && menu.items != null){
menu.items.forEach(item => {
let headerText = widget.addText(item.type)
headerText.applySubheadlineTextStyling()
headerText.textColor = Color.white()
let text = widget.addText(item.dish)
text.leftAlignText()
text.textSize = 10.0
text.textColor = Color.white()
console.log(item.dish)
})
}
}
async function loadImage() {
let imgurl = "https://commentor.dk/wp-content/uploads/2019/11/314x60-commentor.png"
let imgReq = new Request(imgurl)
let image = await imgReq.loadImage()
let widgetImage = widget.addImage(image)
widgetImage.rightAlignImage()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment