Skip to content

Instantly share code, notes, and snippets.

@apiarian
Last active August 1, 2022 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apiarian/ff23ae73cdd72b29e2fa7d570c06e654 to your computer and use it in GitHub Desktop.
Save apiarian/ff23ae73cdd72b29e2fa7d570c06e654 to your computer and use it in GitHub Desktop.
a Scriptable (iOS) widget for chicken.photos
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: pink; icon-glyph: kiwi-bird;
const home = await (new Request("https://chicken.photos")).loadString()
const chickenLine = home.split("\n").filter(x=>x.match(/<a href="\/\d+">/))[0]
const m = chickenLine.match(/a href="([^"]+)"><img .*src="([^"]+)"/)
const chickenUrl = "https://chicken.photos" + m[1]
const chickenTimestamp = m[1].replace("/", "")
const img = await (new Request(m[2])).loadImage()
const widget = new ListWidget()
const label = widget.addText("Top Chicken")
label.centerAlignText()
widget.addSpacer(5)
const imageWidget = widget.addImage(img)
imageWidget.centerAlignImage()
widget.addSpacer(5)
const bottomRow = widget.addStack()
bottomRow.layoutHorizontally()
const dateLabel = bottomRow.addDate(new Date())
dateLabel.applyTimeStyle()
bottomRow.addSpacer()
const subLabel = bottomRow.addText(chickenTimestamp)
subLabel.rightAlignText()
widget.url = chickenUrl
if (!config.runsInWidget) {
await widget.presentLarge()
}
Script.setWidget(widget)
Script.complete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment