TLsqueezer

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

目前为 2016-03-15 提交的版本,查看 最新版本

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