Created
October 13, 2021 06:36
-
-
Save simonbs/eb7abc1b3d187fb5dd7062912127ac28 to your computer and use it in GitHub Desktop.
Scriptable widget that counts down to Apple's Unleashed event on October 18th
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
// 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/YQ09XTW/background.png" | |
const TITLE_IMG_URL = "https://i.ibb.co/qYH3Y9w/text.png" | |
const TITLE_IMG_SIZE = new Size(155, 25) | |
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.presentMedium() | |
} | |
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 | |
widget.addSpacer(5) | |
} | |
if (TITLE != null && TITLE.length > 0) { | |
let wtitle = widget.addText(TITLE) | |
wtitle.font = Font.boldRoundedSystemFont(20) | |
wtitle.textColor = Color.white() | |
widget.addSpacer(2) | |
} | |
let wdate = widget.addDate(eventDate) | |
wdate.applyRelativeStyle() | |
wdate.font = Font.mediumRoundedSystemFont(18) | |
wdate.textColor = Color.white() | |
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
Hey 👋 thanks for this, this is a fantastic addition to my home screen!
I noticed that the background image was pixellated on my iPhone 12 mini and according to this, it’s because of an unpredictable memory limitation in widgets. I uploaded the same image cropped at 500x500 and it loads that in high resolution. It’s in a square ratio for the small size widget though. (Fork)