Created
October 7, 2020 22:01
-
-
Save sebastinez/c2b1749f1189e3321d6d8fea6301de14 to your computer and use it in GitHub Desktop.
A random Chuck Norris Joke generator for the iOS app Scriptable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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