Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use with scriptable.app & are.na to display a random image from a channel onto your phone
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: black; icon-glyph: user-md;
//🕳
// Based on https://gist.github.com/jacopocolo/0e28c4af2e28c9de058480da0c5d4582
// copy and paste into a scriptable widget
// replace the url below with the url if the channel you want to use
// Channel must be public
// uses only images in the channel, does not support text or anything else
const channel = 'https://www.are.na/neil-doshi/a-portal-into-my-phone'
const url = 'https://api.are.na/v2/channels/'+channel.substring(channel.lastIndexOf('/') + 1)+'/contents';
const req = new Request(url)
const res = await req.loadJSON()
const randomBlock = await res.contents[Math.floor(Math.random() * res.contents.length)];
const id = randomBlock.id
const i = await new Request(randomBlock.image.square.url);
const img = await i.loadImage();
if (config.runsInWidget) {
// create and show widget
let widget = createWidget("Are.na random image", img)
Script.setWidget(widget)
Script.complete()
} else {
Safari.open("https://are.na/block/"+id)
}
function createWidget(title, img) {
let w = new ListWidget()
w.backgroundColor = new Color("#fff")
w.backgroundImage = img
w.addSpacer()
return w
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment