Skip to content

Instantly share code, notes, and snippets.

@jacopocolo
Last active July 9, 2025 12:59

Revisions

  1. jacopocolo revised this gist Aug 18, 2020. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions arena-random-image-widget.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,12 @@
    // Variables used by Scriptable.
    // These must be at the very top of the file. Do not edit.
    // icon-color: black; icon-glyph: user-md;
    const url = `https://api.are.na/v2/channels/archillect-selects/contents`

    // 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)];
    @@ -18,11 +23,13 @@ if (config.runsInWidget) {
    Safari.open("https://are.na/block/"+id)
    }


    function createWidget(title, img) {
    let w = new ListWidget()
    w.backgroundColor = new Color("#000000")
    w.backgroundColor = new Color("#1A1A1A")
    w.centerAlignContent()
    let image = w.addImage(img);
    image.centerAlignImage();
    image.imageSize = new Size(150,150)
    return w
    }
    }
  2. jacopocolo created this gist Aug 17, 2020.
    28 changes: 28 additions & 0 deletions arena-random-image-widget.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // Variables used by Scriptable.
    // These must be at the very top of the file. Do not edit.
    // icon-color: black; icon-glyph: user-md;
    const url = `https://api.are.na/v2/channels/archillect-selects/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("#000000")
    w.centerAlignContent()
    let image = w.addImage(img);
    image.centerAlignImage();
    return w
    }