Skip to content

Instantly share code, notes, and snippets.

Last active April 9, 2024 06:04
Show Gist options
  • Save Sillium/f904fb89444bc8dde12cfc07b8fa8728 to your computer and use it in GitHub Desktop.
Save Sillium/f904fb89444bc8dde12cfc07b8fa8728 to your computer and use it in GitHub Desktop.
const apiUrl = ""
let widget = await createWidget()
widget.backgroundColor = new Color("#777777")
if (!config.runsInWidget) {
await widget.presentSmall()
async function createWidget(items) {
let fm = FileManager.local()
let dir = fm.documentsDirectory()
let path = fm.joinPath(dir, "scriptable-telekom.json")
const list = new ListWidget()
try {
let r = new Request(apiUrl)
// API only answers for mobile Safari
r.headers = {
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1"
let data, fresh = 0
try {
// Fetch data from
data = await r.loadJSON()
// Write JSON to iCloud file
fm.writeString(path, JSON.stringify(data, null, 2))
fresh = 1
} catch (err) {
// Read data from iCloud file
data = JSON.parse(fm.readString(path), null)
if (!data || !data.usedPercentage) {
const errorList = new ListWidget()
errorList.addText("Please disable WiFi for initial execution.")
return errorList
const line1 = list.addText("Telekom")
line1.font = Font.mediumSystemFont(12)
const line2 = list.addText(data.usedPercentage + "%")
line2.font = Font.boldSystemFont(36)
line2.textColor =
if (data.usedPercentage >= 75) {
line2.textColor =
} else if (data.usedPercentage >= 90) {
line2.textColor =
const line3 = list.addText(data.usedVolumeStr + " / " + data.initialVolumeStr)
line3.font = Font.mediumSystemFont(12)
let line4, line5
if (data.remainingTimeStr) {
line4 = list.addText("Remaining time:")
line4.font = Font.mediumSystemFont(12)
line5 = list.addText(data.remainingTimeStr)
line5.font = Font.mediumSystemFont(12)
// Gray out if local data instead of Telekom API data:
if (fresh == 0) {
line1.textColor = Color.darkGray()
line2.textColor = Color.darkGray()
line3.textColor = Color.darkGray()
if (data.remainingTimeStr) {
line4.textColor = Color.darkGray()
line5.textColor = Color.darkGray()
} catch(err) {
list.addText("Error fetching JSON from")
// Add time of last widget refresh:
const now = new Date();
const timeLabel = list.addDate(now)
timeLabel.font = Font.mediumSystemFont(10)
timeLabel.textColor = Color.darkGray()
return list
Copy link

Zeigt mir seit heute plötzlich nur noch „undefined“ an. ;(

Copy link

Sillium commented Jul 23, 2021

Zeigt mir seit heute plötzlich nur noch „undefined“ an. ;(

Das ist, weil die Telekom für diesen Monat für alle/viele Kunden unbegrenztes Datenvolumen freigeschaltet hat. Siehe

Copy link

I'm getting Please disable WiFi for initial execution error even when my WiFi is disabled. Please share the working script. Thanks.

Copy link

Since yesterday I‘m getting
2022-06-23 09:05:39: Error on line 16:27: No file to import at Telekom/TelekomDataUsageLibrary_1.0.3.js.

Copy link

Sillium commented Jul 5, 2022

I don't have time to fiddle around with this, but here's a version that should fix a few of the bugs:

Please delete the folder iCloud Drive --> Scriptable --> <script name> depending on how you named the script in your Scriptable app.

Copy link

I also wrote my own version if somebody is interested. However, there is a little thing which im currently trying out. I plan to have an indicator of how much data I can consume this day, so I have the same data also for the next days.

Copy link

Funktioniert auch mit CONGSTAR, da ja im gleichen D-Netz

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