Skip to content

Instantly share code, notes, and snippets.

@alldritt
Last active March 10, 2024 13:28
Show Gist options
  • Save alldritt/1a242ba62f96cb486dbedd76b039dd14 to your computer and use it in GitHub Desktop.
Save alldritt/1a242ba62f96cb486dbedd76b039dd14 to your computer and use it in GitHub Desktop.
A script for Scriptable (https://apps.apple.com/us/app/scriptable/id1405459188) that creates a Midsummer Murders Bot (https://twitter.com/midsomerplots) iOS 14 Widget.
async function loadItems() {
let url = "https://midsomerplots.acrossthecloud.net/plot";
let req = new Request(url);
let json = await req.loadJSON();
return json;
}
function createWidget(plot) {
let w = new ListWidget()
w.backgroundColor = new Color("#b00a0f")
let plotTxt = w.addText(plot)
plotTxt.centerAlignText()
plotTxt.font = Font.callout()
plotTxt.textColor = Color.white()
return w
}
let json = await loadItems();
console.log(json["plot"]);
if (config.runsInWidget) {
let widget = createWidget(json["plot"]);
Script.setWidget(widget);
Script.complete();
} else {
let widget = createWidget(json["plot"]);
widget.presentMedium();
}
@matthewberryman
Copy link

So I shoved a ShareSheet.present(["https://midsomerplots.net/#"+json["seed"]]) into the widget, but there are two issues:
a) It worked when run from Scriptable, however how to trigger it only on tap?
b) In widget form, it throws an error saying the ShareSheets aren't supported for widgets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment