Color Empornium Highest Seeds

Color codes torrents with highest seeds

  1. // ==UserScript==
  2. // @name Color Empornium Highest Seeds
  3. // @description Color codes torrents with highest seeds
  4. // @version 2.2
  5. // @author Monkeys
  6. // @namespace empornium.me
  7. // @include *.empornium.me/torrents.php*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function(){
  12. // *** BEGIN USER ADJUSTABLE VARIABLES *** //
  13. var MODE = 5; //which to use to colorize: 1-seeds, 2-peers, 3-snatched, 4-ratio, 5-peers+seeds
  14. var COLORADJUST = 2; //which color to use: 1-red, 2-green, 3-blue
  15. var LOWEST = 1; //lowest color is: 0-black, 1-white
  16. // *** END USER ADJUSTABLE VARIABLES *** //
  17. //each torrent is a table row:
  18. //<tr class="torrent">
  19. var torrents = document.getElementsByClassName('torrent');
  20. var thislink, links, thisdata;
  21. var numtorrents = torrents.length;
  22. var snatchedi, seedsi, peersi;
  23. var seeds=[];
  24. var peers=[];
  25. var seedsPeers=[];
  26. var snatched=[];
  27. var ratio=[];
  28. var hiseeds=0;
  29. var hipeers=0;
  30. var hiseedsPeers=0;
  31. var hisnatched=0;
  32. var hiratio=0;
  33. var lowseeds=Infinity; //Should I just set this to first torrent
  34. var lowpeers=Infinity;
  35. var lowseedsPeers=Infinity;
  36. var lowsnatched=Infinity;
  37. var lowratio=Infinity;
  38. var MAXCOLORS=255;
  39. function getSuperlatives(arr)
  40. {//return highest and lowest, as well as 2nd highest, lowest
  41. var largest = -Infinity;
  42. var nextLargest = -Infinity;
  43. var smallest = Infinity;
  44. var nextSmallest = Infinity;
  45. for (var ii = 0; ii < arr.length; ii++)
  46. {
  47. var num = arr[ii]; //conver to number
  48. if (num > largest) {
  49. nextLargest = largest;
  50. largest = num;
  51. } else if (num < largest && num > nextLargest) {
  52. nextLargest = num;
  53. }
  54. if (num < smallest) {
  55. nextSmallest = smallest;
  56. smallest = num;
  57. } else if (num > smallest && num < nextSmallest) {
  58. nextSmallest = num;
  59. }
  60. }
  61. //console.log("smallest: ",smallest,", largest: ",largest);
  62. return {smallest: smallest, nextSmallest: nextSmallest, nextLargest: nextLargest, largest: largest};
  63. }
  64. for (var i = 0; i < numtorrents; i++)
  65. {//first pass, collect data
  66. seeds[i]=0;
  67. peers[i]=0;
  68. snatched[i]=0;
  69. ratio[i]=1;
  70. links = torrents[i].getElementsByTagName('td'); //grab links in this torrent
  71. //console.log("\nTorrent #"+i);
  72. for (var j = 0; j< links.length; j++)
  73. {//go through each link, look for seeds, peers, snatched
  74. thislink = links[j].toString(); //href=
  75. thisdata = links[j].innerHTML.toString(); //link text
  76. //console.log("\nthis link: " + thislink + ", this data: " + thisdata);
  77. if (thisdata.indexOf('user.php?id=') != -1 || thisdata.indexOf('anon_name') != -1)
  78. {//found user td, prev 3 are seeds, peers, snatched
  79. snatchedi = j-3;
  80. seedsi = j-2;
  81. peersi = j-1;
  82. //console.log("seedsi: "+seedsi+", j: "+j);
  83. seeds[i] = parseInt(links[seedsi].innerHTML.toString().replace(/\D/g,''))
  84. peers[i] = parseInt(links[peersi].innerHTML.toString().replace(/\D/g,''))
  85. seedsPeers[i] = seeds[i] + peers[i];
  86. snatched[i] = parseInt(links[snatchedi].innerHTML.toString().replace(/\D/g,''))
  87. }
  88. }
  89. ratio[i] = seeds[i]/(peers[i]+1); //+1 to prevent divide by zero
  90. }
  91. var temp;
  92. temp = getSuperlatives(seeds);
  93. hiseeds = temp.nextLargest;
  94. lowseeds = temp.smallest;
  95. temp = getSuperlatives(peers);
  96. hipeers = temp.nextLargest;
  97. lowpeers = temp.smallest;
  98. temp = getSuperlatives(seedsPeers);
  99. hiseedsPeers = temp.nextLargest;
  100. lowseedsPeers = temp.smallest;
  101. temp = getSuperlatives(snatched);
  102. hisnatched = temp.nextLargest;
  103. lowsnatched = temp.smallest;
  104. temp = getSuperlatives(ratio);
  105. hiratio = temp.nextLargest;
  106. lowratio = temp.smallest;
  107. //we now have seeds, peers, snatched, ratio for torrents
  108. //we have to go through again to do styles
  109. for (var i = 0; i < numtorrents; i++)
  110. {//go through each torrent to apply styles
  111. var tempcolor=0;
  112. var fullcolor;
  113. if (MODE==1) tempcolor = Math.round(((seeds[i]-lowseeds)/hiseeds) * MAXCOLORS);
  114. if (MODE==2) tempcolor = Math.round(((peers[i]-lowpeers)/hipeers) * MAXCOLORS);
  115. if (MODE==3) tempcolor = Math.round(((snatched[i]-lowsnatched)/hisnatched) * MAXCOLORS);
  116. if (MODE==4) tempcolor = Math.round(((ratio[i]-lowratio)/hiratio) * MAXCOLORS);
  117. if (MODE==5) tempcolor = Math.round(((seedsPeers[i]-lowseedsPeers)/hiseedsPeers) * MAXCOLORS);
  118. //console.log("Seeds "+seeds[i]+", low: "+lowseeds+", hi: "+hiseeds+", temp: "+tempcolor)
  119. if (LOWEST) tempcolor = MAXCOLORS-tempcolor; //flip in the case of white = low
  120. if (COLORADJUST==1)
  121. {//red
  122. if (LOWEST)
  123. {//white
  124. fullcolor = "rgb("+MAXCOLORS+","+tempcolor+","+tempcolor+")";
  125. }
  126. else
  127. {//black
  128. fullcolor = "rgb("+tempcolor+"0,0)";
  129. }
  130. }
  131. else if (COLORADJUST==2)
  132. {//green
  133. if (LOWEST)
  134. {//white
  135. fullcolor = "rgb("+tempcolor+","+MAXCOLORS+","+tempcolor+")";
  136. }
  137. else
  138. {//black
  139. fullcolor = "rgb(0,"+tempcolor+",0)";
  140. }
  141. }
  142. else
  143. {//blue
  144. if (LOWEST)
  145. {//white
  146. fullcolor = "rgb("+tempcolor+","+tempcolor+","+MAXCOLORS+")";
  147. }
  148. else
  149. {//black
  150. fullcolor = "rgb(0,0,"+tempcolor+")";
  151. }
  152. }
  153. if (torrents[i].className.indexOf('redbar') == -1)
  154. {
  155. torrents[i].style.background = fullcolor;
  156. //torrents[i].style.background = '#ff5644';
  157. }
  158. }
  159. })();