Skip to content

Instantly share code, notes, and snippets.

Last active October 9, 2020 13:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Scriptable widget for random dad Jokes
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
const url = ``
const req = new Request(url)
const res = await req.loadJSON()
if (config.runsInWidget) {
// create and show widget
let widget = createWidget("Dad Joke", `${res.attachmenets[0}.fallback`, "#35363A")
} else {
// make table
let table = new UITable()
// add header
let row = new UITableRow()
row.isHeader = true
row.addText(`Dad Joke`)
// fill data
table.addRow(createRow("Cases", res.attachmenets[0}.fallback))
if (config.runsWithSiri)
// present table
function createRow(title) {
let row = new UITableRow()
return row
function createWidget(pretitle, subtitle, color) {
let w = new ListWidget()
w.backgroundColor = new Color(color)
let preTxt = w.addText(pretitle)
preTxt.textColor = Color.white()
preTxt.textOpacity = 0.8
preTxt.font = Font.systemFont(16)
let subTxt = w.addText(subtitle)
subTxt.textColor = Color.white()
subTxt.textOpacity = 0.8
subTxt.font = Font.systemFont(12)
return w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment