TLsqueezer

groups all releases of same movies and serials into single expendable row

当前为 2018-02-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name TLsqueezer
  3. // @author paxamit
  4. // @description groups all releases of same movies and serials into single expendable row
  5. // @namespace paxamit
  6. // @include http://*.torrentleech.org/torrents/*
  7. // @include https://*.torrentleech.org/torrents/*
  8. // @grant none
  9. // @version 0.22
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. function contentEval(source) {
  14. var script = document.createElement('script')
  15. script.setAttribute("type", "application/javascript")
  16. script.textContent = '(' + source + ')();'
  17.  
  18. document.body.appendChild(script)
  19. document.body.removeChild(script)
  20. }
  21.  
  22. contentEval(function() {
  23. // movies serials
  24. var title_regexp = /.*?([12]\d\d\d|S\d\dE\d\d)/i
  25.  
  26. function guess_title(title) {
  27. var guessed = title_regexp.exec(title)
  28. return guessed ? guessed[0] : title
  29. }
  30.  
  31. function fix_odd_even() {
  32. var odd = true
  33. var count = 0
  34. var was_odd = false
  35.  
  36. $('#torrents tr').each(function () {
  37. var tr = $(this)
  38. if (tr.hasClass('squeezer')) {
  39. count = parseInt(tr.attr('data-count')) + 1
  40. was_odd = odd
  41. }
  42. tr.removeClass('odd even').addClass(odd ? 'odd' : 'even')
  43. odd = --count == 0 ? !was_odd : !odd
  44. })
  45. }
  46.  
  47. $(document).ready(function() {
  48. var elements = $('#torrents tr')
  49.  
  50. elements.each(function() {
  51. var tr = $(this)
  52. this.guessed_title = guess_title(tr.find('.title a').text())
  53. this.guessed_title_lowercase = this.guessed_title.toLowerCase()
  54. this.seeds = parseInt(tr.find('.seeders').text())
  55. this.peers = parseInt(tr.find('.leechers').text())
  56. })
  57.  
  58. for (var x = 0; x < elements.length; ++x) {
  59. var el = elements[x]
  60. if (el.processed)
  61. continue
  62.  
  63. var found_elements = ['#' + $(el).attr('id')]
  64. var peers = el.peers
  65. var seeds = el.seeds
  66.  
  67. for (var y = elements.length - 1; y > x; y--) {
  68. var other = elements[y]
  69. if (!other.processed && el.guessed_title_lowercase == other.guessed_title_lowercase) {
  70. $(el).after(other);
  71. other.processed = true
  72. peers = Math.max(other.peers, peers)
  73. seeds = Math.max(other.seeds, seeds)
  74. found_elements.push('#' + $(other).attr('id'))
  75. }
  76. }
  77. if (found_elements.length > 1) {
  78. var row = '<tr class="squeezer" data-count="' + found_elements.length + '">'
  79. + '<td class="category" style="font-size: 20px; line-height: 44px">'
  80. + found_elements.length + '</td>'
  81. + '<td class="name"><span class="title"><a href="javascript:">'
  82. + el.guessed_title + '</a></span></td>'
  83. + '<td class="quickdownload"></td><td></td><td></td><td></td>'
  84. + '<td class="seeders">' + seeds + '</td>'
  85. + '<td class="leechers">' + peers + '</td><td></td></tr>'
  86.  
  87. var new_row = $(el).before(row).prev()
  88. var ids = $(found_elements.join(','))
  89.  
  90. ids.hide()
  91.  
  92. if (ids.find('.newicon').length > 0)
  93. new_row.find('.name').append('<span class="newicon"> (NEW)</span>')
  94.  
  95. new_row.data('ids', ids)
  96. new_row.data('show', false)
  97.  
  98. ids.find('.title a').each(function () {
  99. this.innerHTML = this.innerHTML.substr(el.guessed_title.length)
  100. })
  101.  
  102. ids.find('.category img').css({position: 'relative', left: '50px' })
  103. ids.find('td.name').prepend('<div style="float: left; width: 55px; height: 20px"></div>')
  104.  
  105. new_row.click(function () {
  106. var show = $(this).data('show')
  107. var ids = $(this).data('ids')
  108. show ? $(ids).hide() : $(ids).show()
  109. $(this).data('show', !show)
  110. })
  111.  
  112. fix_odd_even()
  113. }
  114. }
  115. })
  116. })