Aither++

various QoL improvements to aither

  1. // ==UserScript==
  2. // @name Aither++
  3. // @namespace https://aither.cc/
  4. // @version 0.2
  5. // @description various QoL improvements to aither
  6. // @author Seraph2
  7. // @match https://aither.cc/*
  8. // @grant none
  9. // ==/UserScript==
  10. function statsChange() {
  11. var badges = document.getElementsByClassName("badge-user");
  12. var upload = badges[2];
  13. var download = badges[3];
  14. var ratio = badges[4];
  15. var buffer = badges[5];
  16. var warnings = badges[8];
  17. var bon = badges[9];
  18. var tokens = badges[10];
  19. var stats = [upload, download, ratio, buffer, warnings, bon, tokens];
  20. var counter = 0;
  21. var item;
  22. for (const badge of stats){
  23. // this looks disgusting lol
  24. switch (counter) {
  25. case 0:
  26. item = "upload";
  27. break;
  28. case 1:
  29. item = "download";
  30. break;
  31. case 2:
  32. item = "ratio";
  33. break;
  34. case 3:
  35. item = "buffer";
  36. break;
  37. case 4:
  38. item = "warnings";
  39. break;
  40. case 5:
  41. item = "bon";
  42. break;
  43. case 6:
  44. item = "tokens";
  45. break;
  46. }
  47. var storedValue = localStorage.getItem(item);
  48. var currentValue = badge.textContent.replace( /^\D+/g, '');
  49. // converts all transfer quantities into GB
  50. if (currentValue.includes("TiB")) {
  51. currentValue = currentValue.split(" ")[0] * 1000;
  52. } else {
  53. if (currentValue.includes("GiB")) {
  54. currentValue = currentValue.split(" ")[0];
  55. }
  56. }
  57. var newCurrentValue;
  58. if (item != "bon") {
  59. newCurrentValue = parseFloat(currentValue);
  60. } else {
  61. newCurrentValue = parseInt(currentValue.split(" ").join(""));
  62. }
  63. if (storedValue) {
  64. var change = (newCurrentValue - storedValue);
  65. if (["warnings", "tokens"].includes(item)) {
  66. change = change.toPrecision(1);
  67. } else {
  68. change < 1 ? change = change.toFixed(1) : change = +change.toFixed(2);
  69. }
  70. var ending;
  71. if (["upload", "download", "buffer"].includes(item)) {
  72. ending = " GiB";
  73. } else {
  74. ending = "";
  75. }
  76. if (change && change != 0) {
  77. var span = document.createElement("span");
  78. var changeIsPositive;
  79. Math.sign(change) == 1 ? changeIsPositive = 1 : changeIsPositive = 0;
  80. if (["upload", "ratio", "buffer", "bon", "tokens"].includes(item)) {
  81. if (changeIsPositive == 1) {
  82. span.innerHTML = " +" + change.toString() + ending;
  83. span.style.cssText = "color:green;"
  84. badge.appendChild(span);
  85. } else {
  86. span.innerHTML = " " + change.toString() + ending;
  87. span.style.cssText = "color:red;"
  88. badge.appendChild(span);
  89. }
  90. } else {
  91. if (changeIsPositive == 1) {
  92. span.innerHTML = " +" + change.toString() + ending;
  93. span.style.cssText = "color:red;"
  94. badge.appendChild(span);
  95. } else {
  96. span.innerHTML = " " + change.toString() + ending;
  97. span.style.cssText = "color:green;"
  98. badge.appendChild(span);
  99. }
  100. }
  101. }
  102. localStorage.setItem(item, newCurrentValue);
  103. } else {
  104. localStorage.setItem(item, newCurrentValue);
  105. }
  106. counter++;
  107. }};
  108.  
  109. function randomTorrent() {
  110. var buttons = document.getElementsByClassName("button-left")[0];
  111. var latestTorrent = document.getElementById("facetedSearch").childNodes[1].childNodes[3].childNodes[3].querySelector("tr:not(.success)").childNodes[7].childNodes[1].href; // get the first non-featured torrent in the list
  112. var latestTorrentID = latestTorrent.split("/");
  113. latestTorrentID = parseInt(latestTorrentID[latestTorrentID.length - 1]);
  114. var randomTorrentID = Math.floor(Math.random() * (latestTorrentID - 1) + 1); // generate random torrent ID
  115. var randomURL = "https://aither.cc/torrents/" + randomTorrentID;
  116. var randomButton = document.createElement("a");
  117. randomButton.setAttribute("href", randomURL);
  118. randomButton.innerText = "? Random Torrent";
  119. randomButton.className += "btn btn-sm btn-warning";
  120. buttons.appendChild(randomButton);
  121. };
  122.  
  123. statsChange();
  124. if (window.location.href.endsWith("/torrents")) {
  125. randomTorrent();
  126. }