The Pirate Helper

Enhances your pirating experience!

  1. // ==UserScript==
  2. // @name The Pirate Helper
  3. // @description Enhances your pirating experience!
  4. // @author Noah Keller http://github.com/noahtkeller
  5. // @version 6.0
  6. // @namespace github.com/noahtkeller
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
  8. // @include http*://thepiratebay.*
  9. // @include http*://www.imdb.*/title/tt*
  10. // @grant GM_xmlhttpRequest
  11. // @run-at document-end
  12. // @noframes
  13. // ==/UserScript==
  14.  
  15. var magnet_img = "data:image/gif;base64,R0lGODlhDAAMALMPAOXl5ewvErW1tebm5oocDkVFRePj47a2ts0WAOTk5MwVAIkcDesuEs0VAEZGRv///yH5BAEAAA8ALAAAAAAMAAwAAARB8MnnqpuzroZYzQvSNMroUeFIjornbK1mVkRzUgQSyPfbFi/dBRdzCAyJoTFhcBQOiYHyAABUDsiCxAFNWj6UbwQAOw==";
  16.  
  17. var browser = function (name) {
  18. var n = 'unknown';
  19. if (GM_info.scriptHandler === 'Tampermonkey')
  20. n = 'chrome';
  21. else if (typeof window.opera !== 'undefined')
  22. n = 'opera';
  23. else if (typeof GM_info.scriptWillUpdate === 'number')
  24. n = 'opera';
  25. else if (typeof GM_info.scriptWillUpdate === 'boolean')
  26. n = 'firefox';
  27. return typeof name === 'undefined' ? n : n === name;
  28. };
  29.  
  30. var site = function (check) {
  31. var s = '';
  32. var f = ('' + document.location).split(/^http(s)?\:\/\/(www\.)?/)[3].split('/')[0];
  33. if (typeof f !== 'undefined')
  34. s = f.split(/\.[a-zA-Z](\.[a-zA-Z])?/)[0];
  35. else
  36. s = null;
  37. return typeof check === 'undefined' ? s : s === check;
  38. };
  39.  
  40. var get_data = function (args) {
  41. args.post = typeof args.post === 'undefined' ? false : args.post;
  42. var post_data = '';
  43. if (typeof args.post === 'object')
  44. for (var d in args.post)
  45. post_data += (post_data === '' ? '' : '&') + d + '=' + args.post[d];
  46. GM_xmlhttpRequest({
  47. method: args.post === false ? 'GET' : 'POST',
  48. data: post_data,
  49. url: args.url,
  50. onload: function(rD) {
  51. var xmlDoc = $.parseHTML(rD.responseText);
  52. if (typeof args.onload === 'function')
  53. args.onload(xmlDoc, rD);
  54. },
  55. ontimeout: function(rD) {
  56. var xmlDoc = $.parseHTML(rD.responseText);
  57. if (typeof args.ontimeout === 'function')
  58. args.ontimeout(xmlDoc, rD);
  59. },
  60. onerror: function(rD) {
  61. var xmlDoc = $.parseHTML(rD.responseText);
  62. if (typeof args.onerror === 'function')
  63. args.onerror(xmlDoc, rD);
  64. }
  65. });
  66. };
  67.  
  68.  
  69.  
  70.  
  71. var getTorrents = function() {
  72. var title = $($('h1.header span[itemprop="name"]')[0]).text();
  73. var year = $($('#overview-top > h1 > span.nobr > a')[0]).text();
  74.  
  75. get_data({
  76. url: 'https://thepiratebay.am/search/' + title + ' ' + year + '/0/7/0',
  77. onload: function(data, text) {
  78. var results = $('table#searchResult tbody tr', text.response);
  79. for (var i = 0; i < results.length; i++) {
  80. var result = $(results[i]);
  81. var info = $('td', result);
  82.  
  83. var magnet = $('a[title="Download this torrent using magnet"]', info[1]).attr('href').trim();
  84. var title = $('a.detLink', info[1]).text().trim();
  85. var uploader = $('a.detDesc', info[1]).text().trim();
  86. var seeds = $(info[2]).text().trim();
  87. var leeches = $(info[3]).text().trim();
  88.  
  89. $('<tr><td style="text-align: center;"><a href=\'' + magnet + '\'><img src=\'' + magnet_img + '\'/></a></td><td>' + title + '<br/><small>by: ' + uploader + '</small></td><td style="text-align: center;">' +
  90. seeds + '</td><td style="text-align: center;">' + leeches + '</td></tr>').appendTo('div#torrentResults table');
  91.  
  92. if (i === 0) {
  93. var mag_img = $('<img style="cursor: pointer;" src=\'' + magnet_img + '\'/>');
  94. mag_img.click(function() {
  95. $('#torrentResults').toggle();
  96. });
  97. $('div.infobar').prepend('&nbsp;&nbsp;<span class="ghost">|</span>');
  98. $('div.infobar').prepend(mag_img);
  99. }
  100.  
  101. }
  102.  
  103. }
  104. })
  105. };
  106.  
  107. if (site('imdb')) {
  108. var results = $('<div class="article" id="torrentResults"><table cellpaddng=".2em" cellspacing="0" width="100%"><tr><td style="width: 5%; font-weight: bold; color: red; text-align: center"><span onclick="$(\'#torrentResults\').hide();" style="cursor: pointer;">X</span></td><td style="width: 85%;">Title</td><td style="text-align: center; width: 5%;">S</td><td style="text-align: center;">L</td></tr></table></div>');
  109. results.hide();
  110. results.insertBefore('div.title-overview');
  111. var torrent_data = getTorrents();
  112. } else if (site('thepiratebay')) {
  113. $('div#main-content').css('margin', 0);
  114. }