Forked from mattapperson/Scriptable DailyText widget.js
Last active
October 5, 2020 09:31
-
-
Save brainno722/fd8b846ff6489c5213e787a9a73c0c4a to your computer and use it in GitHub Desktop.
Scriptable Daily Scripture Widget with Picsum/Unsplash Background
This file contains hidden or 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
// Inspired/Forked from https://gist.github.com/mattapperson/114e5267d5bc736fbe616b6205f3df92 (Scriptable DailyText widget.js) | |
let dailyText = await loadText() | |
let widget = await createWidget(dailyText) | |
if (config.runsInWidget) { | |
await widget.presentSmall() | |
} else { | |
// await widget.presentSmall() | |
// opens the Scripture URL in Safari when tapped on the widget | |
let url = "https://www.biblegateway.com/passage/?search=" | |
let param = encodeURI(dailyText.verse.details.reference) | |
Safari.open(url + param + "&version=NIV") | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
async function createWidget(dailyText) { | |
const scripture = dailyText.verse.details.text | |
const ref = dailyText.verse.details.reference | |
const imgURL = "https://picsum.photos/id/1035/400" | |
let titleFont = Font.semiboldSystemFont(12) | |
let txtFont = Font.systemFont(12) | |
let w = new ListWidget() | |
if (imgURL != null) { | |
let imgReq = new Request(imgURL) | |
let img = await imgReq.loadImage() | |
w.backgroundImage = img | |
} | |
let titleTxt = w.addText(scripture) | |
titleTxt.font = titleFont | |
titleTxt.textSize = 12 | |
titleTxt.textColor = new Color("#333") | |
let article = w.addText(ref) | |
article.font = txtFont | |
article.textColor = Color.white() | |
article.textOpacity = 0.8 | |
article.textSize = 12 | |
return w | |
} | |
async function loadText() { | |
const date = new Date() | |
let myurl = `https://beta.ourmanna.com/api/v1/get/?format=json` | |
let req = new Request(myurl) | |
let json = await req.loadJSON() | |
return json | |
} |
Author
brainno722
commented
Oct 5, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment