Update Countdown.js

Add show Date option
This commit is contained in:
Benny 2020-11-10 09:46:19 +01:00 committed by GitHub
parent 11af274988
commit 3ebf8153ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,10 +1,11 @@
// Variables used by Scriptable. // Variables used by Scriptable.
// These must be at the very top of the file. Do not edit. // These must be at the very top of the file. Do not edit.
// icon-color: orange; icon-glyph: hourglass-half; // icon-color: orange; icon-glyph: hourglass-half;
// Version 1.1.0 // Version 1.2.0
let dateForCountdown = '' let dateForCountdown = ''
let icon = '' let icon = ''
let showDate = false
let widgetInputRAW = args.widgetParameter; let widgetInputRAW = args.widgetParameter;
let widgetInput = null; let widgetInput = null;
@ -16,6 +17,9 @@ if (widgetInputRAW !== null) {
} }
dateForCountdown = widgetInput[0].trim() dateForCountdown = widgetInput[0].trim()
icon = widgetInput[1] || '⏳'; icon = widgetInput[1] || '⏳';
if (widgetInput[2] && widgetInput[2].toLowerCase() === 'true') {
showDate = true
}
} else { } else {
throw new Error('No Date set! Please set a Date via Widget parameter like 2020-12-31') throw new Error('No Date set! Please set a Date via Widget parameter like 2020-12-31')
} }
@ -86,10 +90,10 @@ textStack.layoutHorizontally()
textStack.addSpacer() textStack.addSpacer()
textStack.centerAlignContent() textStack.centerAlignContent()
let dayText = textStack.addText(`${remainingDays}`) let daysText = textStack.addText(`${remainingDays}`)
dayText.font = Font.regularSystemFont(50) daysText.font = Font.regularSystemFont(50)
dayText.textColor = new Color(textColor); daysText.textColor = new Color(textColor);
dayText.minimumScaleFactor = 0.5; daysText.minimumScaleFactor = 0.5;
textStack.addSpacer(5) textStack.addSpacer(5)
@ -109,6 +113,14 @@ textStack.addSpacer()
widget.addSpacer() widget.addSpacer()
if(showDate) {
const dateText = widget.addDate(new Date(dateForCountdown))
dateText.font = Font.lightSystemFont(10)
dateText.textColor = new Color(textColor);
dateText.centerAlignText()
widget.addSpacer(5)
}
if(!config.runsInWidget) { if(!config.runsInWidget) {
await widget.presentSmall() await widget.presentSmall()
} else { } else {