Skip to content

Instantly share code, notes, and snippets.

@notsidney
Forked from simonbs/Unleashed.js
Last active November 17, 2021 05:58
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 notsidney/9b7eb80a821b5ef23e79b5e9eccdb3e7 to your computer and use it in GitHub Desktop.
Save notsidney/9b7eb80a821b5ef23e79b5e9eccdb3e7 to your computer and use it in GitHub Desktop.
Scriptable widget that counts down to Apple's Unleashed event on October 18th (small widget)
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: blue; icon-glyph: apple-alt;
const TITLE = ""
const DATE = "2021-10-18T17:00:00Z"
const BG_IMG_URL = "https://i.ibb.co/1rXjnVN/bg-500w.png"
const TITLE_IMG_URL = "https://i.ibb.co/qYH3Y9w/text.png"
const TITLE_IMG_SIZE = new Size(110, 20)
const LINK = "https://www.youtube.com/watch?v=exM1uajp--A"
let widget = await createWidget()
if (config.runsInWidget) {
Script.setWidget(widget)
Script.complete()
} else {
await widget.presentSmall()
}
async function createWidget() {
let eventDate = createEventDate()
let bgImg = await loadBgImage()
let titleImage = await loadTitleImage()
let widget = new ListWidget()
widget.backgroundImage = bgImg
widget.addSpacer()
if (titleImage != null) {
let wimg = widget.addImage(titleImage)
wimg.imageSize = TITLE_IMG_SIZE
wimg.centerAlignImage()
widget.addSpacer(2)
}
if (TITLE != null && TITLE.length > 0) {
let wtitle = widget.addText(TITLE)
wtitle.font = Font.semiboldSystemFont(24)
wtitle.textColor = Color.white()
wtitle.centerAlignText()
widget.addSpacer(2)
}
let wdate = widget.addDate(eventDate)
wdate.applyRelativeStyle()
wdate.font = Font.regularSystemFont(14)
wdate.textColor = Color.white()
wdate.centerAlignText()
if (LINK != null) {
widget.url = LINK
}
return widget
}
function createEventDate() {
let dateFormatter = new DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
dateFormatter.locale = "en_US"
return dateFormatter.date(DATE)
}
async function loadBgImage() {
let req = new Request(BG_IMG_URL)
return await req.loadImage()
}
async function loadTitleImage() {
if (TITLE_IMG_URL != null && TITLE_IMG_URL.length > 0) {
let req = new Request(TITLE_IMG_URL)
return await req.loadImage()
} else {
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment