-
-
Save extratone/a8fe5787b055a47db6f5f33506e1ff2f to your computer and use it in GitHub Desktop.
Scriptable widget that load a random image from an are.na channel
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: black; icon-glyph: user-md; | |
// just replace the url below with the url if the channel you want to use | |
// image channels only, doesnt supoort text or anything else | |
const channel = 'https://www.are.na/una/color-tx32pz_qsu0' | |
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("#1A1A1A") | |
w.centerAlignContent() | |
let image = w.addImage(img); | |
image.centerAlignImage(); | |
image.imageSize = new Size(150,150) | |
return w | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment