mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-06-07 05:57:41 +00:00
Update VodafoneDE.js
v2.3.0: - added Support for flat tariff like "GigaMobil M mit unbegrenzten GB", "GigaMobil XL mit unbegrenzten GB" or other flat tariffs
This commit is contained in:
parent
59fe28e46e
commit
d982b0c970
1 changed files with 592 additions and 608 deletions
|
@ -7,7 +7,7 @@ Version 2.3.0
|
|||
|
||||
Changelog:
|
||||
v2.3.0:
|
||||
- Support for lockscreen widgets added
|
||||
- added Support for flat tariff like "GigaMobil M mit unbegrenzten GB", "GigaMobil XL mit unbegrenzten GB" or other flat tariffs
|
||||
v2.2.2:
|
||||
- fix const variable issue
|
||||
v2.2.1:
|
||||
|
@ -77,12 +77,12 @@ let showRemainingDaysAsProgressbar = true
|
|||
|
||||
// Please add additional values to these list, in case that your contract/tarif isn't supported by these default values.
|
||||
let containerList = ['Daten', 'D_EU_DATA', 'C_DIY_Data_National']
|
||||
let codeList = ['-1', '-5' ,'45500', '40100']
|
||||
let codeList = ['-1', '-5', '45500', '40100']
|
||||
|
||||
// Please add additional values if you see technical descriptions like D_EU_DATA in your widget
|
||||
const descriptionMapping = {
|
||||
'Datenvolumen Inland & EU' : 'Datenvolumen',
|
||||
'GigaDepot-Datenvolumen Inland & EU' : 'GigaDepot-Datenvolumen',
|
||||
'Datenvolumen Inland & EU': 'Datenvolumen',
|
||||
'GigaDepot-Datenvolumen Inland & EU': 'GigaDepot-Datenvolumen',
|
||||
'D_EU_DATA': 'Datenvolumen'
|
||||
}
|
||||
|
||||
|
@ -104,11 +104,9 @@ let widgetInput = null;
|
|||
let user, pass, number, json, cacheUUID
|
||||
if (widgetInputRAW !== null) {
|
||||
const parameter = widgetInputRAW.toString().split("|")
|
||||
|
||||
if(parameter.length > 1) {
|
||||
if (parameter.length > 1) {
|
||||
[user, pass, number, json] = parameter;
|
||||
|
||||
|
||||
if (!user || !pass || !number) {
|
||||
throw new Error("Invalid Widget parameter. Expected format: username|password|phonenumber")
|
||||
}
|
||||
|
@ -146,7 +144,7 @@ if (widgetInputRAW !== null) {
|
|||
// Text sizes
|
||||
const fontSizeData = 11
|
||||
const lineNumberData = 1
|
||||
const minimumScaleFactor = 0.8 // Value between 1.0 and 0.1
|
||||
const minimumScaleFactor = 0.8 //value between 1.0 and 0.1
|
||||
|
||||
// Number of data by Size
|
||||
const numberOfDisplayedDataBySize = {
|
||||
|
@ -186,7 +184,7 @@ if (darkModeSupport) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
async function setupAssistant () {
|
||||
async function setupAssistant() {
|
||||
let parameter = ''
|
||||
|
||||
const promptLoginType = new Alert()
|
||||
|
@ -252,7 +250,7 @@ async function setupAssistant () {
|
|||
let res, data
|
||||
try {
|
||||
res = await req.loadJSON()
|
||||
if(!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0] || !res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']) {
|
||||
if (!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0] || !res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']) {
|
||||
throw new Error('invalid response: ' + JSON.stringify(res))
|
||||
}
|
||||
data = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']
|
||||
|
@ -266,7 +264,7 @@ async function setupAssistant () {
|
|||
}
|
||||
|
||||
const list = data.map(function (o) {
|
||||
return o.usage.map(function(i) {
|
||||
return o.usage.map(function (i) {
|
||||
i.container = o.container || null
|
||||
i.selected = false
|
||||
return i
|
||||
|
@ -289,7 +287,7 @@ async function setupAssistant () {
|
|||
let row = new UITableRow()
|
||||
row.dismissOnSelect = false
|
||||
|
||||
let selectedCell = row.addText((list[i].selected)? "✓" : "")
|
||||
let selectedCell = row.addText((list[i].selected) ? "✓" : "")
|
||||
selectedCell.widthWeight = 5
|
||||
|
||||
let textCell = row.addText(list[i].name)
|
||||
|
@ -374,7 +372,7 @@ function creatProgress(total, havegone) {
|
|||
return context.getImage()
|
||||
}
|
||||
|
||||
function getDiagram(percentage) {
|
||||
function getDiagram(percentage, isFlat) {
|
||||
function drawArc(ctr, rad, w, deg) {
|
||||
bgx = ctr.x - rad
|
||||
bgy = ctr.y - rad
|
||||
|
@ -426,9 +424,15 @@ function getDiagram(percentage) {
|
|||
)
|
||||
canvas.setTextAlignedCenter()
|
||||
canvas.setTextColor(textColor)
|
||||
canvas.setFont(Font.boldSystemFont(canvTextSize))
|
||||
canvas.drawTextInRect(`${percentage}%`, canvTextRect)
|
||||
|
||||
canvas.setFont(Font.boldSystemFont(108))
|
||||
if (isFlat === true) {
|
||||
const infinitySize = canvSize / 2;
|
||||
canvas.setFont(Font.boldSystemFont(infinitySize));
|
||||
const textRect = new Rect(0, infinitySize / 3, canvSize, canvSize);
|
||||
canvas.drawTextInRect(`∞`, textRect);
|
||||
} else {
|
||||
canvas.drawTextInRect(`${percentage}%`, canvTextRect);
|
||||
}
|
||||
return canvas.getImage()
|
||||
}
|
||||
|
||||
|
@ -448,20 +452,6 @@ function getTimeRemaining(endtime) {
|
|||
}
|
||||
}
|
||||
|
||||
function getTotalValues(v) {
|
||||
let totalValues;
|
||||
if (v.unitOfMeasure !== 'MB') {
|
||||
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure} von ${v.total} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure}`
|
||||
} else if (parseInt(v.total) < 1000) {
|
||||
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} MB von ${v.total} MB`
|
||||
} else {
|
||||
let GB = ((showRemainingContingent ? v.remaining : v.used) / 1024).toFixed(2)
|
||||
let totalGB = (v.total / 1024).toFixed(2)
|
||||
totalValues = `${GB} GB von ${totalGB} GB`
|
||||
}
|
||||
return totalValues
|
||||
}
|
||||
|
||||
async function getSessionCookiesViaNetworkLogin() {
|
||||
let req;
|
||||
req = new Request("https://www.vodafone.de/mint/rest/session/start")
|
||||
|
@ -536,11 +526,11 @@ async function getUsage(user, pass, number) {
|
|||
}
|
||||
try {
|
||||
let res = await req.loadJSON()
|
||||
if(!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0]) {
|
||||
if (!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0]) {
|
||||
if (debug) {
|
||||
console.log(JSON.stringify(res, null, 2))
|
||||
}
|
||||
throw new Error("Invalid Response")
|
||||
|
||||
}
|
||||
console.log("unbilled-usage loaded")
|
||||
if (debug) {
|
||||
|
@ -569,7 +559,7 @@ async function getUsage(user, pass, number) {
|
|||
}
|
||||
|
||||
|
||||
for(let i = 0; i < container.length; i++) {
|
||||
for (let i = 0; i < container.length; i++) {
|
||||
for (let j = 0; j < container[i]['usage'].length; j++) {
|
||||
if (codeList.includes(container[i]['usage'][j]['code'])) {
|
||||
usage.push(container[i]['usage'][j])
|
||||
|
@ -581,7 +571,7 @@ async function getUsage(user, pass, number) {
|
|||
console.log(ErrorMsg)
|
||||
|
||||
const listOfCodeInResponse = []
|
||||
for(let i = 0; i < container.length; i++) {
|
||||
for (let i = 0; i < container.length; i++) {
|
||||
for (let j = 0; j < container[i]['usage'].length; j++) {
|
||||
listOfCodeInResponse.push(`Code: "${container[i]['usage'][j].code}" for "${container[i]['usage'][j].description}"`)
|
||||
}
|
||||
|
@ -617,7 +607,7 @@ var today = new Date()
|
|||
const files = FileManager.local()
|
||||
|
||||
// Set up cache
|
||||
const cacheNamePostfix = ((number) ? number.substr(number.length - 4) : 'networkLogin') + ( cacheUUID ? `-${cacheUUID}` : '')
|
||||
const cacheNamePostfix = ((number) ? number.substr(number.length - 4) : 'networkLogin') + (cacheUUID ? `-${cacheUUID}` : '')
|
||||
const cachePath = files.joinPath(files.cacheDirectory(), "widget-vodafone-" + cacheNamePostfix)
|
||||
const cacheExists = files.fileExists(cachePath)
|
||||
const cacheDate = cacheExists ? files.modificationDate(cachePath) : 0
|
||||
|
@ -655,38 +645,15 @@ try {
|
|||
}
|
||||
}
|
||||
|
||||
const lockscreenWidget = config.widgetFamily.includes('accessory')
|
||||
|
||||
// Create Widget
|
||||
let widget = new ListWidget();
|
||||
|
||||
if(!lockscreenWidget) {
|
||||
widget.setPadding(10, 10, 10, 10)
|
||||
}
|
||||
widget.setPadding(10, 10, 10, 10)
|
||||
|
||||
if (data !== undefined) {
|
||||
if(debug) {
|
||||
if (debug) {
|
||||
console.log(JSON.stringify(data, null, 2))
|
||||
}
|
||||
if(lockscreenWidget) {
|
||||
let stack = widget.addStack()
|
||||
stack.layoutHorizontally()
|
||||
let v = data.usage[0]
|
||||
if(config.widgetFamily !== "accessoryInline") {
|
||||
const percentage = (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
|
||||
stack.addImage(getDiagram(percentage));
|
||||
}
|
||||
if(config.widgetFamily === "accessoryRectangular"){
|
||||
stack.addSpacer(5)
|
||||
|
||||
}
|
||||
|
||||
if(config.widgetFamily !== "accessoryCircular"){
|
||||
const totalValues = getTotalValues(v)
|
||||
stack.centerAlignContent()
|
||||
stack.addText(totalValues)
|
||||
}
|
||||
} else {
|
||||
const gradient = new LinearGradient()
|
||||
gradient.locations = [0, 1]
|
||||
gradient.colors = [
|
||||
|
@ -732,17 +699,37 @@ stack.addImage(getDiagram(percentage));
|
|||
column = row.addStack()
|
||||
column.layoutVertically()
|
||||
column.centerAlignContent()
|
||||
|
||||
const percentage = (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
|
||||
const percentage = v.total > 100000000 ? 100 : (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
|
||||
const isFlat = v.total >= 100000000
|
||||
const imageStack = column.addStack()
|
||||
imageStack.layoutHorizontally()
|
||||
imageStack.addSpacer()
|
||||
imageStack.addImage(getDiagram(percentage));
|
||||
imageStack.addImage(getDiagram(percentage, isFlat));
|
||||
imageStack.addSpacer()
|
||||
column.addSpacer(2)
|
||||
|
||||
// Total Values
|
||||
let totalValues = getTotalValues(v)
|
||||
let totalValues;
|
||||
if (v.unitOfMeasure !== 'MB') {
|
||||
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure} von ${v.total} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure}`
|
||||
} else if (parseInt(v.total) < 1000) {
|
||||
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} MB von ${v.total} MB`
|
||||
} else if (parseInt(v.total) >= 100000000) {
|
||||
if (showRemainingContingent === true) {
|
||||
totalValues = `Flat`
|
||||
} else {
|
||||
if (v.used <= 1024) {
|
||||
totalValues = `${v.used} MB verbraucht.`
|
||||
} else {
|
||||
let usedGB = (v.used / 1024).toFixed(2)
|
||||
totalValues = `${usedGB} GB verbraucht.`
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let GB = ((showRemainingContingent ? v.remaining : v.used) / 1024).toFixed(2)
|
||||
let totalGB = (v.total / 1024).toFixed(2)
|
||||
totalValues = `${GB} GB von ${totalGB} GB`
|
||||
}
|
||||
textStack = column.addStack()
|
||||
textStack.layoutHorizontally()
|
||||
textStack.addSpacer()
|
||||
|
@ -772,7 +759,7 @@ stack.addImage(getDiagram(percentage));
|
|||
if (data.endDate) {
|
||||
widget.addSpacer(5)
|
||||
let remainingDays = getTimeRemaining(data.endDate).days + 2
|
||||
if(data.billDate && showRemainingDaysAsProgressbar) {
|
||||
if (data.billDate && showRemainingDaysAsProgressbar) {
|
||||
const startDate = new Date(data.billDate)
|
||||
const endDate = new Date(data.endDate)
|
||||
const total = (endDate - startDate) / (1000 * 60 * 60 * 24)
|
||||
|
@ -792,7 +779,7 @@ stack.addImage(getDiagram(percentage));
|
|||
remainingDaysText.centerAlignText()
|
||||
remainingDaysText.textColor = textColor
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
let fallbackText = widget.addText("Es ist ein Fehler aufgetreten! Bitte prüfen Sie die Logs direkt in der App.")
|
||||
fallbackText.font = Font.mediumSystemFont(12)
|
||||
|
@ -804,9 +791,6 @@ if (!config.runsInWidget) {
|
|||
case 'small': await widget.presentSmall(); break;
|
||||
case 'medium': await widget.presentMedium(); break;
|
||||
case 'large': await widget.presentLarge(); break;
|
||||
case 'accessoryRectangular': await widget.presentAccessoryRectangular(); break;
|
||||
case 'accessoryCircular': await widget.presentAccessoryCircular(); break;
|
||||
case 'accessoryInline': await widget.presentAccessoryInline(); break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue