Created
May 30, 2022 08:09
-
-
Save simonbs/d8653fcb5aca93acb14a91c8d0b767c8 to your computer and use it in GitHub Desktop.
Scriptable widget counting down to WWDC22
This file contains 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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: cyan; icon-glyph: apple-alt; | |
const TITLE = "WWDC22" | |
const PAST_EVENT_TEXT = "Have a great Dub Dub!" | |
const DATE = "2022-06-06T17:00:00Z" | |
const BG_IMG_URL = "https://i.ibb.co/9t9CbxX/wwdc22.png" | |
const LINK = "https://developer.apple.com/wwdc22/" | |
let widget = await createWidget() | |
if (config.runsInWidget) { | |
Script.setWidget(widget) | |
Script.complete() | |
} else { | |
await widget.presentMedium() | |
} | |
async function createWidget() { | |
let eventDate = createEventDate() | |
let bgImg = await loadBgImage() | |
let textColor = new Color("#C6E1E6") | |
let widget = new ListWidget() | |
widget.backgroundImage = bgImg | |
widget.addSpacer() | |
if (TITLE != null && TITLE.length > 0) { | |
let wtitle = widget.addText(TITLE) | |
wtitle.font = Font.boldSystemFont(26) | |
wtitle.textColor = textColor | |
widget.addSpacer(2) | |
} | |
let now = new Date() | |
let isPastStart = now.getTime() >= eventDate.getTime() | |
if (isPastStart && PAST_EVENT_TEXT != null && PAST_EVENT_TEXT.length > 0) { | |
let wsubtitle = widget.addText(PAST_EVENT_TEXT) | |
wsubtitle.font = Font.mediumSystemFont(20) | |
wsubtitle.textColor = textColor | |
} else { | |
let wdate = widget.addDate(eventDate) | |
wdate.applyRelativeStyle() | |
wdate.font = Font.mediumSystemFont(22) | |
wdate.textColor = textColor | |
} | |
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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment