Last active
March 16, 2021 15:08
-
-
Save rudotriton/9d11ce1101ff1269f56844871b3fd536 to your computer and use it in GitHub Desktop.
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
const url = "https://xkcd.com/info.0.json" | |
const req = new Request(url) | |
const { img: imgUrl } = await req.loadJSON() | |
const imgReq = await new Request(imgUrl) | |
const img = await imgReq.loadImage() | |
// for development, displays the widget if run | |
const debug = false; | |
if (config.runsInWidget) { | |
// create and show widget | |
let widget = createWidget(img) | |
Script.setWidget(widget) | |
Script.complete() | |
} else if (debug) { | |
let widget = createWidget(img); | |
await widget.presentMedium(); | |
} else { | |
Safari.open(imgUrl) | |
} | |
function createWidget(img) { | |
let widget = new ListWidget(); | |
widget.url = imgUrl; | |
let image = widget.addImage(img); | |
image.centerAlignImage(); | |
const [width, height] = getDimensions(config.widgetFamily); | |
image.imageSize = new Size(width, height); | |
return widget; | |
} | |
function getDimensions(size) { | |
switch (size) { | |
case "small": | |
return [150, 150]; | |
case "medium": | |
return [300, 150]; | |
case "large": | |
return [300, 300]; | |
default: | |
return [150, 150]; | |
break; | |
} | |
} |
@bendiscover Honestly, I forgot I had this here, but I updated it, so now it looks like my current widget script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get an error. "widget.centerAlignContent()" is undefined/not a function