Last active
April 15, 2022 18:57
-
-
Save o-o-o-o-o/d73544bfaabc6554c6e7346dbce53010 to your computer and use it in GitHub Desktop.
Use with scriptable.app & are.na to display a random image from a channel onto your phone
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. | |
// 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