Scriptable widget for random dad Jokes
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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
const url = `https://icanhazdadjoke.com/slack` | |
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") | |
Script.setWidget(widget) | |
Script.complete() | |
} else { | |
// make table | |
let table = new UITable() | |
// add header | |
let row = new UITableRow() | |
row.isHeader = true | |
row.addText(`Dad Joke`) | |
table.addRow(row) | |
// fill data | |
table.addRow(createRow("Cases", res.attachmenets[0}.fallback)) | |
if (config.runsWithSiri) | |
Speech.speak(res.attachmenets[0}.fallback) | |
// present table | |
table.present() | |
} | |
function createRow(title) { | |
let row = new UITableRow() | |
row.addText(title) | |
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) | |
w.addSpacer(5) | |
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