-
-
Save thettenhausen/b3b19af5c68713761a616d2db985b31c to your computer and use it in GitHub Desktop.
Anzeige der verbleibenden Tage bis zur Fusion BLACK in einem Widget
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
| const endDate = '07/01/2021 09:00:00 AM'; | |
| const fontColor = new Color("#918A8A") | |
| const daysTillText = 'Days until Fusion' | |
| const logoUrl = 'https://www.fusion-festival.de/typo3conf/ext/user_fusion_x/Resources/Public/Images/Icons/favicon-96x96.png' | |
| const widgetUrl = "https://www.fusion-festival.de" | |
| const daysFont = Font.ultraLightSystemFont(70) | |
| const dummyFont = Font.lightSystemFont(14) | |
| const widget = await createWidget() | |
| widget.backgroundColor = new Color("#F00480") | |
| if (!config.runsInWidget) { | |
| await widget.presentSmall() | |
| } | |
| Script.setWidget(widget) | |
| Script.complete() | |
| async function createWidget() { | |
| let daysText, dummyText, row, row2 | |
| const widget = new ListWidget() | |
| widget.url = widgetUrl | |
| const logoReq = new Request(logoUrl) | |
| const logoImg = await logoReq.loadImage() | |
| const wimg = widget.addImage(logoImg) | |
| wimg.imageSize = new Size(175,44) | |
| wimg.centerAlignImage() | |
| widget.addSpacer(10) | |
| row = widget.addStack() | |
| row.layoutHorizontally() | |
| row.centerAlignContent() | |
| row.size = new Size(190, 60) | |
| row.addSpacer() | |
| daysText = row.addText(calculateDays(endDate) + '') | |
| daysText.textColor = fontColor | |
| daysText.font = daysFont | |
| row.addSpacer() | |
| row2 = widget.addStack() | |
| row2.layoutHorizontally() | |
| row2.centerAlignContent() | |
| row2.size = new Size(190, 18) | |
| row2.addSpacer() | |
| dummyText = row2.addText(daysTillText) | |
| dummyText.textColor = fontColor | |
| dummyText.font = dummyFont | |
| row2.addSpacer() | |
| return widget | |
| } | |
| function calculateDays(targetDate) { | |
| let days, startDate, timeRemaining; | |
| targetDate = new Date(targetDate); | |
| startDate = new Date(); | |
| timeRemaining = parseInt((targetDate.getTime() - startDate.getTime()) / 1000); | |
| if (timeRemaining >= 0) { | |
| days = parseInt(timeRemaining / 86400); | |
| timeRemaining = (timeRemaining % 86400); | |
| return parseInt(days, 10); | |
| } else { | |
| return '???'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment