Skip to content

Instantly share code, notes, and snippets.

@mattapperson
Last active March 30, 2024 20:48
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mattapperson/114e5267d5bc736fbe616b6205f3df92 to your computer and use it in GitHub Desktop.
Save mattapperson/114e5267d5bc736fbe616b6205f3df92 to your computer and use it in GitHub Desktop.
let dailyText = await loadText()
if (config.runsInWidget) {
let widget = createWidget(dailyText)
Script.setWidget(widget)
Script.complete()
} else {
Safari.open(dailyText.url.replace('/wol/','jwpub://' ))
}
function createWidget(dailyText) {
const scripture = extractScripture(dailyText).replace(/<[^>]*>?/gm, '');
const text = extractText(dailyText).replace(/<[^>]*>?/gm, '')
let w = new ListWidget()
w.backgroundColor = new Color("#4a6da7")
w.centerAlignContent()
let titleTxt = w.addText(scripture)
titleTxt.applyHeadlineTextStyling()
titleTxt.textSize = 13
titleTxt.textColor = Color.white()
let article = w.addText(text)
article.applyBodyTextStyling()
article.textColor = Color.white()
article.textOpacity = 0.8
article.textSize = 12
return w
}
async function loadText() {
const date = new Date()
let url = `https://wol.jw.org/wol/dt/r1/lp-e/${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
let req = new Request(url)
let json = await req.loadJSON()
return json.items[0]
}
function extractScripture(item) {
let regex = /<em>(.*)<\/em>/
let html = item.content
let matches = html.match(regex)
if (matches && matches.length >= 2) {
return matches[1]
} else {
return null
}
}
function extractText(item) {
let html = item.content.split("<p")[2].split(/>(.+)/)[1]
if (html) {
return html
} else {
return null
}
}
@juri-diener
Copy link

Hey really cool widget. One thing i don't get it. Can someone explain me where it says it runs daily?

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