Comcast Internet Usage Percent

display percent in larger usage meter, also show where you should be based on number of days in the month

当前为 2017-01-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Comcast Internet Usage Percent
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description display percent in larger usage meter, also show where you should be based on number of days in the month
  6. // @author Harry Groover
  7. // @match https://customer.xfinity.com/MyServices/Internet/
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var timer = setInterval(updateMeter, 250),
  15. d = new Date(),
  16. m = d.getMonth(),
  17. dotm = d.getDate()+(d.getHours()/24)+(d.getMinutes()/6000), // append current hours and minutes for more accuracy
  18. lastDay = new Date(d.getYear(), m+1, 0).getDate(),
  19. datePercent = Math.round((dotm/(lastDay+1))*100); // add one to calculate end of the day instead of beginning
  20. function updateMeter() {
  21. var usageBar = $('.usage-meter-widget').find('.cui-usage-bar'),
  22. dateBar,
  23. percentUsed, plan, usage;
  24.  
  25. if (usageBar.length > 0) {
  26. plan = usageBar.data('plan');
  27. usage = usageBar.children().data('used');
  28. percentUsed = Math.round(usage/plan*100);
  29. usageBar.css('height', '30px');
  30. usageBar.children().css('width', percentUsed+'%').append('<span style="font-size: 1.2em; margin-top: 6.5px; margin-right: 10px; display: block; text-align: right; color: #ffffff;">'+percentUsed+'%</span>');
  31. dateBar = usageBar.clone();
  32. dateBar.children().css('width', datePercent+'%').find('span').text(datePercent+'%');
  33. dateBar.insertAfter(usageBar);
  34. $('<h5>What You Should Be Under</h5>').insertBefore(dateBar);
  35. clearInterval(timer);
  36. }
  37. }
  38. })();