Skip to content

Instantly share code, notes, and snippets.

@ward
Created October 7, 2015 08:20
Show Gist options
  • Save ward/4cdd3c5b19727f7378b7 to your computer and use it in GitHub Desktop.
Save ward/4cdd3c5b19727f7378b7 to your computer and use it in GitHub Desktop.
Proximus usage bookmarklet
/**
* Run on https://admit.belgacom.be/eservices/wps/myportal/myBillAndUsage
* Shows the ratios of your current used bandwidth (used / total) and of
* how much of the month has gone by (current amount passed / total amount in month)
*/
function parseBytes(s) {
var gm = /^(\d+) GB (\d+) MB$/;
var g = /^(\d+) GB$/;
var m = /^(\d+) MB$/;
var match;
if (match = s.match(gm)) {
return parseInt(match[1]) * 1024 + parseInt(match[2]);
} else if (match = s.match(g)) {
return parseInt(match[1]) * 1024;
} else if (match = s.match(m)) {
return parseInt(match[1]);
} else {
return 0;
}
}
var today = new Date();
var firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
var lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0);
var vars = document.getElementsByTagName('var');
var used = parseBytes(vars.item(0).innerHTML);
var total = parseBytes(vars.item(1).innerHTML);
var dayRatio = (today - firstDay) / (lastDay - firstDay);
var byteRatio = used / total;
var p = document.createElement('p');
p.innerHTML = 'Byte ratio: ' + (byteRatio*100) + '; Day ratio: ' + (dayRatio*100) + '.';
var before = vars[0].parentNode.nextSibling;
var dad = vars[0].parentNode.parentNode;
dad.insertBefore(p, before);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment