Last active
February 23, 2025 21:01
-
-
Save apiarian/ff23ae73cdd72b29e2fa7d570c06e654 to your computer and use it in GitHub Desktop.
a Scriptable (iOS) widget for chicken.photos
This file contains hidden or 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. | |
// 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
Whatever "Top Chicken" javascript ios widget is, I'm here for it.