mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-06-04 12:37:42 +00:00
Countdown widget added
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
47ee81e4b8
commit
b8ac3bdaa5
5 changed files with 107 additions and 0 deletions
107
Countdown/Countdown.js
Normal file
107
Countdown/Countdown.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
// Variables used by Scriptable.
|
||||
// These must be at the very top of the file. Do not edit.
|
||||
// icon-color: orange; icon-glyph: hourglass-half;
|
||||
// Version 1.0.0
|
||||
|
||||
let dateForCountdown = ''
|
||||
let icon = ''
|
||||
|
||||
let widgetInputRAW = args.widgetParameter;
|
||||
let widgetInput = null;
|
||||
|
||||
if (widgetInputRAW !== null) {
|
||||
widgetInput = widgetInputRAW.toString().split(";");
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(widgetInput[0].trim()) === false) {
|
||||
throw new Error('Invalid Date format. Please use the ISO8601 format: 2020-12-31')
|
||||
}
|
||||
dateForCountdown = widgetInput[0].trim()
|
||||
icon = widgetInput[1] || '⏳';
|
||||
} else {
|
||||
throw new Error('No Date set! Please set a Date via Widget parameter like 2020-12-31')
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
let backColor; //Widget background color
|
||||
let backColor2; //Widget background color
|
||||
let textColor; //Widget text color
|
||||
|
||||
if (Device.isUsingDarkAppearance()) {
|
||||
backColor = '111111';
|
||||
backColor2 = '222222';
|
||||
textColor = 'EDEDED';
|
||||
} else {
|
||||
backColor = 'A04000';
|
||||
backColor2 = 'DC7633';
|
||||
textColor = 'EDEDED';
|
||||
}
|
||||
|
||||
function getTimeRemaining(endtime){
|
||||
const total = Date.parse(endtime) - Date.parse(new Date());
|
||||
const seconds = Math.floor( (total/1000) % 60 );
|
||||
const minutes = Math.floor( (total/1000/60) % 60 );
|
||||
const hours = Math.floor( (total/(1000*60*60)) % 24 );
|
||||
const days = Math.floor( total/(1000*60*60*24) );
|
||||
|
||||
return {
|
||||
total,
|
||||
days,
|
||||
hours,
|
||||
minutes,
|
||||
seconds
|
||||
};
|
||||
}
|
||||
let remainingDays = getTimeRemaining(dateForCountdown).days + 1;
|
||||
|
||||
// Create Widget
|
||||
let widget = new ListWidget();
|
||||
|
||||
widget.setPadding(10, 10, 10, 10)
|
||||
|
||||
const gradient = new LinearGradient()
|
||||
gradient.locations = [0, 1]
|
||||
gradient.colors = [
|
||||
new Color(backColor),
|
||||
new Color(backColor2)
|
||||
]
|
||||
widget.backgroundGradient = gradient
|
||||
|
||||
|
||||
let provider = widget.addText(icon + " Countdown")
|
||||
provider.font = Font.mediumSystemFont(12)
|
||||
provider.textColor = new Color(textColor)
|
||||
|
||||
widget.addSpacer()
|
||||
|
||||
let textStack = widget.addStack();
|
||||
textStack.layoutHorizontally()
|
||||
textStack.addSpacer()
|
||||
textStack.centerAlignContent()
|
||||
|
||||
let dayText = textStack.addText(`${remainingDays}`)
|
||||
dayText.font = Font.regularSystemFont(50)
|
||||
dayText.textColor = new Color(textColor);
|
||||
dayText.minimumScaleFactor = 0.5;
|
||||
|
||||
textStack.addSpacer(5)
|
||||
|
||||
let postfixText;
|
||||
if (remainingDays === 1) {
|
||||
postfixText = textStack.addText('Tag')
|
||||
|
||||
} else {
|
||||
postfixText = textStack.addText('Tage')
|
||||
}
|
||||
postfixText.font = Font.regularSystemFont(20)
|
||||
postfixText.textColor = new Color(textColor);
|
||||
|
||||
textStack.addSpacer()
|
||||
|
||||
widget.addSpacer()
|
||||
|
||||
if(!config.runsInWidget) {
|
||||
await widget.presentSmall()
|
||||
} else {
|
||||
// Tell the system to show the widget.
|
||||
Script.setWidget(widget)
|
||||
Script.complete()
|
||||
}
|
BIN
Countdown/previewDark.jpeg
Normal file
BIN
Countdown/previewDark.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
Countdown/previewDark2.jpeg
Normal file
BIN
Countdown/previewDark2.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
Countdown/previewLight.jpeg
Normal file
BIN
Countdown/previewLight.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
Countdown/previewLight2.jpeg
Normal file
BIN
Countdown/previewLight2.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
Loading…
Add table
Reference in a new issue