mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-06-04 04:27:40 +00:00
Show Remaining Days + MegaByte Support + MeinVodafone Login
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
26d047e5a6
commit
0231ef5e06
4 changed files with 112 additions and 26 deletions
18
README.md
18
README.md
|
@ -26,22 +26,22 @@ If you have widget ideas, please feel free and share those ideas with me via Git
|
|||
This widget loads the remaining data volume via the MyVodafone API. For this purpose, an automatic login via the cell phone network is performed, therefore it is necessary that the WIFI is not active for the first usage.
|
||||
After the first usage, the informations are cached and will be used in case of an active WIFI Connection. The cached information will be also used to prevent the API from a lot of request. The TTL (Time To Live) of the Cache can be setup at the beginning of the script (default is 60 min)
|
||||
|
||||
It is possible to overwrite the used colors of the widget. To overwrite the colors, you have to add four color codes separated by | to the widget parameter option: `BackgroundColor|TextColor|CircleFillColor|CircleStrokeColor`
|
||||
[[Download]](https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/VodafoneDE/VodafoneDE.js)
|
||||
|
||||
### Options
|
||||
#### Set own color scheme
|
||||
To overwrite the colors, you have to add four color codes separated by | to the widget parameter option: `BackgroundColor|TextColor|CircleFillColor|CircleStrokeColor`
|
||||
|
||||
Example: `D32D1F|EDEDED|EDEDED|B0B0B0`
|
||||
|
||||
If no parameter are set or not four colors are set the default color set for light or dark Mode will be used.
|
||||
|
||||
[[Download]](https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/VodafoneDE/VodafoneDE.js)
|
||||
#### Use MeinVodafone Login
|
||||
It is possible to add the MeinVodafone Credentails to the beginning of script, which allows the widget to update itself even with active WIFI or show data usage of another mobile contract.
|
||||
|
||||
_Roadmap_:
|
||||
* Add GigaDepot volume
|
||||
* MegaByte Support
|
||||
* Show remaining Days
|
||||
|
||||
_Contributors_:
|
||||
### Contributors
|
||||
* [Necriso](https://github.com/Necriso)
|
||||
|
||||
_Credits_:
|
||||
### Credits
|
||||
* Sillium for the inspiration https://gist.github.com/Sillium/f904fb89444bc8dde12cfc07b8fa8728
|
||||
* Chaeimg for the Circle diagram (https://github.com/chaeimg/battCircle)
|
||||
|
|
|
@ -3,9 +3,13 @@
|
|||
// icon-color: red; icon-glyph: broadcast-tower;
|
||||
|
||||
/**************
|
||||
Version 1.0.3
|
||||
Version 1.1.0
|
||||
|
||||
Changelog:
|
||||
v1.1.0:
|
||||
- Login via MeinVodafone Login added
|
||||
- Show Remaining Days
|
||||
- MegaByte Support added for tariffs with <= 1 GB
|
||||
v1.0.3:
|
||||
- CallYa Support
|
||||
- Write more useful information in the log, so that you can add support yourself if necessary
|
||||
|
@ -26,6 +30,11 @@ Credits:
|
|||
// How many minutes should the cache be valid
|
||||
let cacheMinutes = 60;
|
||||
|
||||
// Login via MeinVodafone Login.
|
||||
const username = "";
|
||||
const password = "";
|
||||
const phonenumber = ""; // with leading 49 instead of 0. Example: 4917212345678
|
||||
|
||||
// Please add additional values to these list, in case that your contract/tarif isn't supported by these default values.
|
||||
const containerList = ['Daten', 'D_EU_DATA']
|
||||
const codeList = ['-1', '45500']
|
||||
|
@ -104,7 +113,23 @@ function drawArc(ctr, rad, w, deg) {
|
|||
}
|
||||
}
|
||||
|
||||
async function getSessionCookies() {
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
async function getSessionCookiesViaNetworkLogin() {
|
||||
let req;
|
||||
req = new Request("https://www.vodafone.de/mint/rest/session/start")
|
||||
req.method = "POST";
|
||||
|
@ -124,13 +149,47 @@ async function getSessionCookies() {
|
|||
let res = await req.loadJSON()
|
||||
return { cookies: req.response.cookies, msisdn: res.msisdn}
|
||||
} catch (e) {
|
||||
console.log("Login vailed! Please check if Wifi is disabled.")
|
||||
console.log("Login failed! Please check if Wifi is disabled.")
|
||||
throw new Error(`Login failed with HTTP-Status-Code ${req.response.statusCode}`)
|
||||
}
|
||||
};
|
||||
|
||||
async function getSessionCookiesViaMeinVodafoneLogin() {
|
||||
let req;
|
||||
req = new Request("https://www.vodafone.de/mint/rest/session/start")
|
||||
req.method = "POST";
|
||||
req.headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
|
||||
req.body = JSON.stringify({
|
||||
"clientType": "Portal",
|
||||
"username": username,
|
||||
"password": password,
|
||||
})
|
||||
try {
|
||||
let res = await req.loadJSON()
|
||||
return { cookies: req.response.cookies}
|
||||
} catch (e) {
|
||||
console.log("Login failed!")
|
||||
throw new Error(`Login failed with HTTP-Status-Code ${req.response.statusCode}`)
|
||||
}
|
||||
};
|
||||
|
||||
async function getUsage() {
|
||||
let {cookies, msisdn} = await getSessionCookies();
|
||||
let cookies, msisdn;
|
||||
if (username !== "" && password !== "" && msisdn !== "") {
|
||||
console.log("Login via MeinVodafone")
|
||||
let { cookies: c }= await getSessionCookiesViaMeinVodafoneLogin();
|
||||
cookies = c;
|
||||
msisdn = phonenumber;
|
||||
} else {
|
||||
console.log("Login via Network")
|
||||
let { cookies: c, msisdn: m } = await getSessionCookiesViaNetworkLogin();
|
||||
cookies = c;
|
||||
msisdn = m;
|
||||
}
|
||||
let CookieValues = cookies.map(function(v){
|
||||
return v.name + "=" + v.value
|
||||
})
|
||||
|
@ -180,10 +239,17 @@ async function getUsage() {
|
|||
throw new Error(ErrorMsg)
|
||||
}
|
||||
|
||||
|
||||
let endDate = datenvolumen.endDate;
|
||||
if (endDate == null) {
|
||||
endDate = res['serviceUsageVBO']['billDetails']['billCycleEndDate'] || null
|
||||
}
|
||||
|
||||
return {
|
||||
total: datenvolumen.total,
|
||||
used: datenvolumen.used,
|
||||
remaining: datenvolumen.remaining
|
||||
remaining: datenvolumen.remaining,
|
||||
endDate
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Loading usage data failed")
|
||||
|
@ -240,6 +306,7 @@ let widget = new ListWidget();
|
|||
widget.setPadding(10, 10, 10, 10)
|
||||
|
||||
if (data !== undefined) {
|
||||
console.log(data)
|
||||
if (useGradient) {
|
||||
const gradient = new LinearGradient()
|
||||
gradient.locations = [0, 1]
|
||||
|
@ -252,10 +319,20 @@ if (data !== undefined) {
|
|||
widget.backgroundColor = new Color(backColor)
|
||||
}
|
||||
|
||||
let provider = widget.addText("Vodafone")
|
||||
let firstLineStack = widget.addStack()
|
||||
|
||||
let provider = firstLineStack.addText("Vodafone")
|
||||
provider.font = Font.mediumSystemFont(12)
|
||||
provider.textColor = new Color(textColor)
|
||||
|
||||
// Last Update
|
||||
firstLineStack.addSpacer()
|
||||
let lastUpdateText = firstLineStack.addDate(lastUpdate)
|
||||
lastUpdateText.font = Font.mediumSystemFont(8)
|
||||
lastUpdateText.rightAlignText()
|
||||
lastUpdateText.applyTimeStyle()
|
||||
lastUpdateText.textColor = Color.lightGray()
|
||||
|
||||
widget.addSpacer()
|
||||
|
||||
let remainingPercentage = (100 / data.total * data.remaining).toFixed(0);
|
||||
|
@ -285,20 +362,29 @@ if (data !== undefined) {
|
|||
widget.addSpacer()
|
||||
|
||||
// Total Values
|
||||
let remainingGB = (data.remaining / 1024).toFixed(2)
|
||||
let totalGB = (data.total / 1024).toFixed(0)
|
||||
let totalValuesText = widget.addText(`${remainingGB} GB von ${totalGB} GB`)
|
||||
let totalValues;
|
||||
if (parseInt(data.total) < 1000) {
|
||||
totalValues = `${data.remaining} MB von ${data.total} MB`
|
||||
} else {
|
||||
let remainingGB = (data.remaining / 1024).toFixed(2)
|
||||
let totalGB = (data.total / 1024).toFixed(0)
|
||||
totalValues = `${remainingGB} GB von ${totalGB} GB`
|
||||
}
|
||||
let totalValuesText = widget.addText(totalValues)
|
||||
totalValuesText.font = Font.mediumSystemFont(12)
|
||||
totalValuesText.centerAlignText()
|
||||
totalValuesText.textColor = new Color(textColor)
|
||||
totalValuesText.textColor = new Color(textColor)
|
||||
|
||||
// Last Update
|
||||
widget.addSpacer(5)
|
||||
let lastUpdateText = widget.addDate(lastUpdate)
|
||||
lastUpdateText.font = Font.mediumSystemFont(10)
|
||||
lastUpdateText.centerAlignText()
|
||||
lastUpdateText.applyTimeStyle()
|
||||
lastUpdateText.textColor = Color.lightGray()
|
||||
// Remaining Days
|
||||
if (data.endDate) {
|
||||
widget.addSpacer(5)
|
||||
let remainingDays = getTimeRemaining(data.endDate).days + 1
|
||||
let remainingDaysText = widget.addText(`${remainingDays} Tage verleibend`)
|
||||
remainingDaysText.font = Font.mediumSystemFont(8)
|
||||
remainingDaysText.centerAlignText()
|
||||
remainingDaysText.textColor = new Color(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)
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 30 KiB |
Binary file not shown.
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 52 KiB |
Loading…
Add table
Reference in a new issue