Skip to content

Instantly share code, notes, and snippets.

@matthewberryman
Forked from alldritt/murderbot.js
Last active January 14, 2023 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewberryman/ec49ec938d72cf8a4133da946881f17f to your computer and use it in GitHub Desktop.
Save matthewberryman/ec49ec938d72cf8a4133da946881f17f 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?characterLimit=200";
let req = new Request(url);
let json;
try {
json = await req.loadJSON();
} catch (e) {
throw e;
}
return json;
}
function createWidget(json) {
let w = new ListWidget();
w.backgroundColor = new Color("#000099");
w.url = "https://midsomerplots.net/#" + json.seed;
let plotTxt = w.addText(json.plot);
plotTxt.centerAlignText();
plotTxt.font = Font.callout();
plotTxt.textColor = Color.white();
return w;
}
try {
let json = await loadItems();
if (config.runsInWidget) {
let widget = createWidget(json);
Script.setWidget(widget);
Script.complete();
} else if (config.runsWithSiri) {
Speech.speak(json.plot);
Script.complete();
} else {
let widget = createWidget(json);
widget.presentMedium();
Speech.speak(json.plot);
}
} catch (e) {
console.error(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment