-
-
Save alldritt/1a242ba62f96cb486dbedd76b039dd14 to your computer and use it in GitHub Desktop.
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(); | |
} |
alldritt
commented
Oct 3, 2020
Thanks so much for this! At least on my iPhone 8 (currently awaiting the 12) I have been finding the plots are truncated even with a full-width widget. I have introduced a new characterLimit querystring parameter that can be passed in. It's a little inelegant still but at characterLimit=200 doesn't seem to take too long to generate a plot and thus far in testing all the plots fit. Updated script: https://gist.github.com/matthewberryman/ec49ec938d72cf8a4133da946881f17f
Thanks! We could also go to a larger Widget (Full Size). I'll look to see if there is a way to scale the font size down to make the entire plot text fit the box, though that might make things unreadable.
I have to say, I love what you've done. The plots often make my day, especially in our current crazy times.
Yeah I had a look at the UI stuff you've done and IMHO (and this is very subjective on my part) I think widget size and in particular the font size is fine (especially now I've reached middle age and need reading glasses :), but feel free to change of course. Also feel free to submit a PR to the content distro to add your script and any docs you feel like writing.
If you pass in the full json back you could set the widget url / pop up a ShareSheet to link to "https://midsomerplots.net/#"+json["seed"]
so people can then share the plot. I realised after setting up shareable urls using only the (Unix time) seed that I need an ugly hack (that I have in my head but need to code up) to preserve past-shared URLS in future if I add more content, due to the way I use the seed. I also realised today that the Mersenne twister library I am using is missing 64 bit time support so some time between now and 2038 I will need to fix that based on 64 bit MT libraries floating around in other language.
Glad you are liking the plots—they are meant to be fun.
I've updated my fork of the gist that sets w.url
as a simple example, but it feels clunky - takes you to the web site and then you need to click share there to copy to clipboard. I will have a look at ShareSheet tomorrow (UTC+1100) unless someone beats me :)
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.