Skip to content

Instantly share code, notes, and snippets.

@sebastinez
Created October 7, 2020 22:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebastinez/c2b1749f1189e3321d6d8fea6301de14 to your computer and use it in GitHub Desktop.
Save sebastinez/c2b1749f1189e3321d6d8fea6301de14 to your computer and use it in GitHub Desktop.
A random Chuck Norris Joke generator for the iOS app Scriptable
const w = new ListWidget()
w.backgroundImage = await getBgImage()
const joke = w.addText(await getJoke())
joke.textColor = Color.white()
joke.minimumScaleFactor=0.1;
joke.shadowOffset = new Point(2,2)
joke.shadowRadius = 2
joke.centerAlignText()
joke.font = Font.boldSystemFont(20)
Script.setWidget(w)
Script.complete()
if(!config.runsInWidget) {
w.presentMedium()
}
async function getJoke() {
let url = "https://api.chucknorris.io/jokes/random"
const r = new Request(url)
let json = await r.loadJSON().catch(e=>{w.addText(e.message)})
return json.value
}
async function getBgImage() {
const req = new Request("https://fotos.perfil.com/2018/11/17/420/0/chuck-norris-11172018-394376.jpg")
return await req.loadImage()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment