mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-04-19 15:27:40 +00:00
Update number-of-covild-19-vaccinations.js
- prevent error if user deletes Widget-"Parameter" - format numbers with more readable units and their correct abbreviation
This commit is contained in:
parent
cbd5006125
commit
9e3a696a3d
1 changed files with 42 additions and 10 deletions
|
@ -1,11 +1,19 @@
|
||||||
|
// Home: https://github.com/ThisIsBenny/iOS-Widgets/tree/main/number-of-covild-19-vaccinations
|
||||||
|
// Variables used by Scriptable.
|
||||||
|
// These must be at the very top of the file. Do not edit.
|
||||||
|
// icon-color: red; icon-glyph: syringe;
|
||||||
// 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: red; icon-glyph: syringe;
|
// icon-color: red; icon-glyph: syringe;
|
||||||
|
|
||||||
/**************
|
/**************
|
||||||
Version 1.0.1
|
Version 1.0.2
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
v1.0.2
|
||||||
|
- prevent error if user deletes Widget-"Parameter"
|
||||||
|
- format numbers with more readable units and their correct abbreviation
|
||||||
|
|
||||||
v1.0.1:
|
v1.0.1:
|
||||||
- fix sorting issue
|
- fix sorting issue
|
||||||
|
|
||||||
|
@ -32,7 +40,7 @@ config.widgetFamily = config.widgetFamily || 'large'
|
||||||
let widgetInputRAW = args.widgetParameter;
|
let widgetInputRAW = args.widgetParameter;
|
||||||
let selectedState
|
let selectedState
|
||||||
|
|
||||||
if (widgetInputRAW !== null) {
|
if (widgetInputRAW !== null && widgetInputRAW !== "" ) {
|
||||||
if (/^Baden-Württemberg|Bayern|Berlin|Brandenburg|Bremen|Hamburg|Hessen|Mecklenburg-Vorpommern|Niedersachsen|Nordrhein-Westfalen|Rheinland-Pfalz|Saarland|Sachsen|Sachsen-Anhalt|Schleswig-Holstein|Thüringen$/.test(widgetInputRAW.toString().trim()) === false) {
|
if (/^Baden-Württemberg|Bayern|Berlin|Brandenburg|Bremen|Hamburg|Hessen|Mecklenburg-Vorpommern|Niedersachsen|Nordrhein-Westfalen|Rheinland-Pfalz|Saarland|Sachsen|Sachsen-Anhalt|Schleswig-Holstein|Thüringen$/.test(widgetInputRAW.toString().trim()) === false) {
|
||||||
throw new Error('Kein gültiges Bundesland. Bitte prüfen Sie die Eingabe.')
|
throw new Error('Kein gültiges Bundesland. Bitte prüfen Sie die Eingabe.')
|
||||||
}
|
}
|
||||||
|
@ -279,19 +287,32 @@ if (config.widgetFamily === 'large') {
|
||||||
imageStack1.addSpacer()
|
imageStack1.addSpacer()
|
||||||
column.addSpacer(2)
|
column.addSpacer(2)
|
||||||
|
|
||||||
const total1 = parseInt((result.states[selectedState].total / 1000).toFixed(0)).toLocaleString('de')
|
let total1 = (result.states[selectedState].total / 1000).toFixed(0)
|
||||||
|
let total1unit = " Tsd."
|
||||||
|
// if total is a million or more, format as millions and not thousands
|
||||||
|
if ( result.states[selectedState].total > 999999 ){
|
||||||
|
total1 = (result.states[selectedState].total / 1000000).toFixed(0)
|
||||||
|
total1unit = " Mio."
|
||||||
|
}
|
||||||
let vaccinated1
|
let vaccinated1
|
||||||
if (result.states[selectedState].vaccinated > 999) {
|
let vaccinated1unit = ""
|
||||||
vaccinated1 = parseInt((result.states[selectedState].vaccinated / 1000).toFixed(0)).toLocaleString('de') + 't'
|
if ( result.states[selectedState].vaccinated > 999999){
|
||||||
|
vaccinated1 = (result.states[selectedState].vaccinated / 1000000).toFixed(0)
|
||||||
|
vaccinated1unit = " Mio."
|
||||||
|
}
|
||||||
|
else if ( result.states[selectedState].vaccinated > 999 ) {
|
||||||
|
vaccinated1 = (result.states[selectedState].vaccinated / 1000).toFixed(0)
|
||||||
|
vaccinated1unit = " Tsd."
|
||||||
} else {
|
} else {
|
||||||
vaccinated1 = result.states[selectedState].vaccinated
|
vaccinated1 = result.states[selectedState].vaccinated
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const numbersText1Stack = column.addStack()
|
const numbersText1Stack = column.addStack()
|
||||||
numbersText1Stack.layoutHorizontally()
|
numbersText1Stack.layoutHorizontally()
|
||||||
numbersText1Stack.addSpacer()
|
numbersText1Stack.addSpacer()
|
||||||
|
|
||||||
const numbersText1 = numbersText1Stack.addText(`${vaccinated1} von ${total1}t`)
|
const numbersText1 = numbersText1Stack.addText(`${vaccinated1}${vaccinated1unit} von ${total1}${total1unit}`)
|
||||||
numbersText1.font = Font.systemFont(fontSize2)
|
numbersText1.font = Font.systemFont(fontSize2)
|
||||||
numbersText1Stack.addSpacer()
|
numbersText1Stack.addSpacer()
|
||||||
|
|
||||||
|
@ -316,14 +337,25 @@ if (config.widgetFamily === 'large') {
|
||||||
imageStack2.addImage(getDiagram(result.quote));
|
imageStack2.addImage(getDiagram(result.quote));
|
||||||
imageStack2.addSpacer()
|
imageStack2.addSpacer()
|
||||||
|
|
||||||
const total2 = parseInt((result.total / 1000).toFixed(0)).toLocaleString('de')
|
let total2 = (result.total / 1000).toFixed(0)
|
||||||
let vaccinated2 = parseInt((result.vaccinated / 1000).toFixed(0)).toLocaleString('de')
|
let total2unit = " Tsd."
|
||||||
|
// if total is a million or more, format as millions and not thousands
|
||||||
|
if ( result.total > 999999 ){
|
||||||
|
total2 = (result.total / 1000000).toFixed(0)
|
||||||
|
total2unit = " Mio."
|
||||||
|
}
|
||||||
|
let vaccinated2 = (result.vaccinated / 1000).toFixed(0)
|
||||||
|
let vaccinated2unit = " Tsd."
|
||||||
|
if ( result.vaccinated > 999999 ){
|
||||||
|
vaccinated2 = (result.vaccinated / 1000000).toFixed(0)
|
||||||
|
vaccinated2unit = " Mio."
|
||||||
|
}
|
||||||
|
|
||||||
const numbersText2Stack = column2.addStack()
|
const numbersText2Stack = column2.addStack()
|
||||||
numbersText2Stack.layoutHorizontally()
|
numbersText2Stack.layoutHorizontally()
|
||||||
numbersText2Stack.addSpacer()
|
numbersText2Stack.addSpacer()
|
||||||
|
|
||||||
const numbersText2 = numbersText2Stack.addText(`${vaccinated2}t von ${total2}t`)
|
const numbersText2 = numbersText2Stack.addText(`${vaccinated2}${vaccinated2unit} von ${total2}${total2unit}`)
|
||||||
numbersText2.font = Font.systemFont(fontSize2)
|
numbersText2.font = Font.systemFont(fontSize2)
|
||||||
numbersText2Stack.addSpacer()
|
numbersText2Stack.addSpacer()
|
||||||
|
|
||||||
|
@ -356,4 +388,4 @@ if (!config.runsInWidget) {
|
||||||
} else {
|
} else {
|
||||||
Script.setWidget(widget)
|
Script.setWidget(widget)
|
||||||
}
|
}
|
||||||
Script.complete()
|
Script.complete()
|
||||||
|
|
Loading…
Add table
Reference in a new issue