Blutopia actual buffer

Shows your actual buffer(to 1.0 ratio) next to blutopias buffer(0.4 ratio)

  1. // ==UserScript==
  2. // @name Blutopia actual buffer
  3. // @description Shows your actual buffer(to 1.0 ratio) next to blutopias buffer(0.4 ratio)
  4. // @match http://blutopia.xyz/*
  5. // @match https://blutopia.xyz/*
  6. // @exclude /https?:\/\/blutopia\.xyz\/login/
  7. // @exclude /https?:\/\/blutopia\.xyz\/register/
  8. // @exclude /https?:\/\/blutopia\.xyz\/password\/reset/
  9. // @exclude /https?:\/\/blutopia\.xyz\/username\/reminder/
  10. // @exclude /https?:\/\/blutopia\.xyz\/application/
  11. // @exclude /https?:\/\/blutopia\.xyz\/rss\/.*/
  12. // @version 0.0.1.20200714150437
  13. // @namespace https://greasyfork.org/users/656892
  14. // ==/UserScript==
  15. try {
  16. var fileSize = /(\d+\.\d+) (([PTG]i)?B)/;
  17. var li = document.getElementById("main-content").getElementsByClassName("list-inline")[0].getElementsByTagName("li");
  18. var upload = toGiB(trimHTML(li[2].innerHTML));
  19. var download = toGiB(trimHTML(li[3].innerHTML));
  20.  
  21. li[5].innerHTML = li[5].innerHTML.replace("iB", "iB / " + GiBtoString((upload - download)));
  22. } catch(err) { /*prob on a page without the header thing*/ }
  23.  
  24. function trimHTML(string) {
  25. return string.replace(/(<([^>]+)>)|\n|/,"").replace(/ {2,}/, " ").trim();
  26. }
  27.  
  28. function toGiB(string) {
  29. var regexp = string.match(fileSize);
  30. if(regexp == null) {
  31. return 0;
  32. }
  33. var size = parseFloat(regexp[1]);
  34. var unit = regexp[2];
  35. var factor;
  36. switch(unit) {
  37. case "PiB":
  38. factor = 1024*1024;
  39. break;
  40. case "TiB":
  41. factor = 1024;
  42. break;
  43. case "GiB":
  44. factor = 1;
  45. break;
  46. default:
  47. return 0;
  48. }
  49. return size * factor;
  50. }
  51.  
  52. function GiBtoString(GiB) {
  53. var TiB = 1024;
  54. var PiB = TiB*TiB;
  55. var unit = " GiB";
  56. var size = GiB;
  57.  
  58. if(GiB >= TiB && GiB < PiB) {
  59. unit = " TiB";
  60. size = GiB/TiB;
  61. } else if(GiB >= PiB) {
  62. unit = " PiB";
  63. size = GiB/PiB;
  64. }
  65.  
  66. return size.toFixed(2) + unit;
  67. }