Skip to content

Instantly share code, notes, and snippets.

@timwillsie
Last active June 2, 2021 04:09
Show Gist options
  • Select an option

  • Save timwillsie/32db56505cbbf49f01e1dd11b095c1c8 to your computer and use it in GitHub Desktop.

Select an option

Save timwillsie/32db56505cbbf49f01e1dd11b095c1c8 to your computer and use it in GitHub Desktop.
Anzeige der verbleibenden Tage bis zum WOA in einem Widget
const endDate = '08/04/2022 05:00:00 PM';
const fontColor = new Color("#918A8A")
const daysTillText = 'Tage bis Wacken'
const logoUrl = 'https://www.wacken.com/fileadmin/user_upload/_ts2-2_/logo_1x-min.png'
const widgetUrl = "https://www.wacken.com"
const daysFont = Font.ultraLightSystemFont(70)
const dummyFont = Font.lightSystemFont(14)
const widget = await createWidget()
widget.backgroundColor = new Color("#000000")
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 '???';
}
}
@timwillsie

timwillsie commented Oct 23, 2020

Copy link
Copy Markdown
Author

Heftig inspiriert (sprich: abgekupfert) von dm-toilet-paper.js und telekom.js.
Dort ist auch die Installation beschrieben.

Update:
Ich wurde darum gebeten explizit darauf hinzuweisen wessen Code ich hierfür wiederverwendet habe, was ich in diesem Nachtrag machen möchte. Also: Dieses Widget hätte ich ohne die Vorarbeit von marco79cgn und Sillium nicht so schnell realisieren können! Vielen Dank!

@timwillsie

Copy link
Copy Markdown
Author

Bildschirmfoto 2020-10-23 um 10 39 49

@gnrmarcel

Copy link
Copy Markdown

Wäre schon cool, wenn Du den Original Ersteller des Codes / Widgets hier erwähnst!

@timwillsie

Copy link
Copy Markdown
Author

Wäre schon cool, wenn Du den Original Ersteller des Codes / Widgets hier erwähnst!

Ich dachte dass ich das hiermit getan hätte, aber wahrscheinlich hast du Recht und ich sollte nicht nur deren Gists verlinken sondern noch einmal explizit die Autoren erwähnen. Werde den Kommentar noch einmal ergänzen. Danke für den Hinweis!

@gnrmarcel

Copy link
Copy Markdown

Alles gut. Ich nutze auch gern vordefinierte Scripts und passe mir diese an ... nur dann finde ich es fair, wenn die Person auch erwähnt wird, der die meiste Arbeit damit hatte 👍

@timwillsie

Copy link
Copy Markdown
Author

Code für 2022 aktualisiert :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment