Greasy Fork 支持简体中文。

Gazelle : File Count

Shows the number of tracks and/or files in each torrent

  1. // ==UserScript==
  2. // @name Gazelle : File Count
  3. // @namespace notwhat/apollo/pth
  4. // @description Shows the number of tracks and/or files in each torrent
  5. // @version 2.0.0
  6. // @match https://notwhat.cd/torrents.php*id=*
  7. // @match https://apollo.rip/torrents.php*id=*
  8. // @match https://passtheheadphones.me/torrents.php*id=*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. // _____________________________________________________________
  14. // _____________ Preferences ___________________________________
  15.  
  16.  
  17. // How to display the file count:
  18.  
  19. // 1 = Total number of files in torrent (15)
  20. // 2 = Number of tracks out of total files (12/15)
  21. // 3 = Number of tracks plus extra files (12+3)
  22. // 4 = Only the number of tracks (12)
  23.  
  24. var display = 3;
  25.  
  26.  
  27.  
  28. // Highlight editions with conflicting track counts:
  29.  
  30. var checkEditions = true;
  31.  
  32.  
  33.  
  34. // Highlight torrents with extra files (usually artwork)
  35. // exceeding this size (in MB; 0 = disable):
  36.  
  37. var extraSizeLimit = 40;
  38.  
  39.  
  40.  
  41. // Always show the size of extras when hovering over a
  42. // torrent size (false = only the highlighted ones):
  43.  
  44. var tooltipAll = false;
  45.  
  46.  
  47. // _____________________________________________________________
  48. // __________ End of Preferences _______________________________
  49.  
  50.  
  51.  
  52.  
  53. function toBytes(size) {
  54. var num = parseFloat(size.replace(',', ''));
  55. var i = ' KMGT'.indexOf(size.charAt(size.length-2));
  56. return Math.round(num * Math.pow(1024, i));
  57. }
  58.  
  59.  
  60. function toSize(bytes) {
  61. if (bytes <= 0) return '0 B';
  62. var i = Math.floor(Math.log(bytes) / Math.log(1024));
  63. var num = Math.round(bytes / Math.pow(1024, i));
  64. return num + ' ' + ['B', 'KB', 'MB', 'GB', 'TB'][i];
  65. }
  66.  
  67.  
  68. function addStyle(css) {
  69. var s = document.createElement('style');
  70. s.type = 'text/css';
  71. s.textContent = css;
  72. document.head.appendChild(s);
  73. }
  74.  
  75.  
  76. function setTitle(elem, str) {
  77. elem.title = str;
  78. if (window.jQuery && jQuery.fn.tooltipster) {
  79. jQuery(elem).tooltipster({ delay: 500, maxWidth: 400 });
  80. }
  81. }
  82.  
  83.  
  84.  
  85. var table = document.getElementById('torrent_details');
  86. if (table) {
  87.  
  88. var isMusic = !!document.querySelector('.box_artists');
  89. extraSizeLimit = extraSizeLimit * 1048576;
  90.  
  91. addStyle(
  92. '.gmfc_files { cursor: pointer; }' +
  93. '.gmfc_extrasize { background-color: rgba(228, 169, 29, 0.12) !important; }'
  94. );
  95.  
  96.  
  97. table.rows[0].insertCell(1).innerHTML = '<strong>Files</strong>';
  98.  
  99. var rows = table.querySelectorAll('.edition, .torrentdetails');
  100. for (var i = rows.length; i--; ) {
  101. ++rows[i].cells[0].colSpan;
  102. }
  103.  
  104.  
  105. rows = table.getElementsByClassName('torrent_row');
  106. var editions = {};
  107.  
  108. for (var i = rows.length; i--; ) {
  109.  
  110. var fileRows = rows[i].nextElementSibling.
  111. querySelectorAll('.filelist_table tr:not(:first-child)');
  112. var numFiles = fileRows.length;
  113. var numTracks = 0;
  114.  
  115. if (isMusic) {
  116. var extraSize = 0;
  117.  
  118. for (var j = numFiles; j--; ) {
  119. if (/\.(flac|mp3|m4a|ac3|dts)\s*$/i.test(fileRows[j].cells[0].textContent)) {
  120. ++numTracks;
  121. } else if (extraSizeLimit || tooltipAll) {
  122. extraSize += toBytes(fileRows[j].cells[1].textContent);
  123. }
  124. }
  125.  
  126. if (checkEditions) {
  127. var ed = /edition_\d+/.exec(rows[i].className)[0];
  128. editions[ed] = ed in editions && editions[ed] !== numTracks ? -1 : numTracks;
  129. }
  130.  
  131. var largeExtras = extraSizeLimit && extraSize > extraSizeLimit;
  132. if (largeExtras || tooltipAll) {
  133. var sizeCell = rows[i].cells[1];
  134. setTitle(sizeCell, 'Extras: ' + toSize(extraSize));
  135. if (largeExtras) {
  136. sizeCell.classList.add('gmfc_extrasize');
  137. }
  138. }
  139.  
  140. } else {
  141. display = 0;
  142. }
  143.  
  144. var cell = rows[i].insertCell(1);
  145. cell.textContent = display < 2 ? numFiles : numTracks;
  146. cell.className = 'gmfc_files';
  147. if (display != 3) {
  148. cell.className += ' number_column';
  149. } else {
  150. var numExtras = numFiles - numTracks;
  151. if (numExtras) {
  152. var sml = document.createElement('small');
  153. sml.textContent = '+' + numExtras;
  154. cell.appendChild(sml);
  155. }
  156. }
  157. if (display == 2) {
  158. cell.textContent += '/' + numFiles;
  159. }
  160.  
  161. }
  162.  
  163.  
  164. if (checkEditions) {
  165. var sel = '';
  166. for (var ed in editions) {
  167. if (editions.hasOwnProperty(ed) && editions[ed] < 1) {
  168. sel += [sel ? ',.' : '.', ed, '>.gmfc_files'].join('');
  169. }
  170. }
  171. if (sel) addStyle(sel + '{background-color: rgba(236, 17, 0, 0.09) !important;}');
  172. }
  173.  
  174.  
  175. // Show filelist on filecount click
  176.  
  177. table.addEventListener('click', function (e) {
  178.  
  179. function get(type) {
  180. return document.getElementById([type, id].join('_'));
  181. }
  182.  
  183. var elem = e.target.nodeName != 'SMALL' ? e.target : e.target.parentNode;
  184. if (elem.classList.contains('gmfc_files')) {
  185.  
  186. var id = elem.parentNode.id.replace('torrent', '');
  187. var tEl = get('torrent');
  188. var fEl = get('files');
  189. var show = [tEl.className, fEl.className].join().indexOf('hidden') > -1;
  190.  
  191. tEl.classList[show ? 'remove' : 'add']('hidden');
  192. fEl.classList[show ? 'remove' : 'add']('hidden');
  193.  
  194. if (show) {
  195. var sections = ['peers', 'downloads', 'snatches', 'reported', 'logs'];
  196. for (var i = sections.length; i--; ) {
  197. var el = get(sections[i]);
  198. if (el) el.classList.add('hidden');
  199. }
  200. }
  201.  
  202. }
  203. }, false);
  204.  
  205. }