[nyaa.si] Batch Download

Allows batch download of all displayed results in one single click.

当前为 2017-06-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name [nyaa.si] Batch Download
  3. // @description Allows batch download of all displayed results in one single click.
  4. // @author MetalTxus
  5. // @version 1.0.1
  6.  
  7. // @include /^https?:\/\/\S*nyaa.si\S*/
  8. // @require http://code.jquery.com/jquery-3.2.1.min.js
  9. // @icon https://avatars3.githubusercontent.com/u/28658394?s=48
  10. // @namespace https://greasyfork.org/users/8682
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var DEBUGGING_ENABLED = false,
  17. MAGNET_SELECTOR = 'a[href*="/download/"]',
  18. DOWNLOADS_SELECTOR = '.mt-hidden-downloads',
  19. DOWNLOAD_INTERVAL = 1000;
  20.  
  21. var fileCount = 0;
  22.  
  23. function appendBatchDownloadButton () {
  24. fileCount = $(MAGNET_SELECTOR).length;
  25.  
  26. if (fileCount) {
  27. $('.torrent-list').append(
  28. '<tr style="background: none;">' +
  29. '<td colspan="9" align="center">' +
  30. '<a title="Download all" href="#" class="mt-batch-download">< Download all (' + fileCount + ') ><br>' +
  31. '<i class="fa fa-fw fa-magnet"></i>' +
  32. '</a>' +
  33. '</td>' +
  34. '</tr>');
  35.  
  36. $('.mt-batch-download').click(downloadAll);
  37.  
  38. $('body').append($('<div class="mt-hidden-downloads">').hide());
  39. }
  40. }
  41.  
  42. function downloadAll(event) {
  43. event.preventDefault();
  44.  
  45. $(DOWNLOADS_SELECTOR).html('');
  46.  
  47. $(MAGNET_SELECTOR).each(function (i, downloadLink) {
  48. setTimeout(function () {
  49. var url = downloadLink.href;
  50. downloadSingle(url);
  51.  
  52. if (DEBUGGING_ENABLED) {
  53. var label = $(downloadLink).parents('tr').find('a[href^="/view/"]').eq(0).text();
  54. console.debug('[nyaa.si] Batch Download: Downloading torrent ' + (i + 1) + '/' + fileCount + ' ("' + label + '", ' + url + ')');
  55. }
  56.  
  57. }, i * DOWNLOAD_INTERVAL);
  58. });
  59. }
  60.  
  61. function downloadSingle (url) {
  62. $(DOWNLOADS_SELECTOR).append($('<iframe>').attr('src', url));
  63. }
  64.  
  65. function initialize () {
  66. appendBatchDownloadButton();
  67. }
  68.  
  69. initialize();
  70.  
  71.  
  72. })();