[nyaa.si] Batch Download

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

当前为 2020-03-01 提交的版本,查看 最新版本

  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.1.0
  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=44
  10. // @namespace https://greasyfork.org/users/8682
  11. // @grant GM_xmlhttpRequest
  12. // ==/UserScript==
  13.  
  14. (() => {
  15. 'use strict';
  16.  
  17. const DOWNLOAD_INTERVAL = 150;
  18.  
  19. const jQuery = window.jQuery;
  20.  
  21. const magnets = jQuery('a[href*="magnet:"]');
  22.  
  23. const appendBatchDownloadButton = () => {
  24. const fileCount = magnets.length;
  25. if (fileCount) {
  26. const downloadAll = () => {
  27. downloadNext(magnets.toArray());
  28. }
  29.  
  30. const downloadNext = (anchors) => {
  31. const anchor = anchors.pop();
  32. const url = anchor.href.split('&dn=')[0];
  33. const magnetTab = window.open(url);
  34. setTimeout(() => magnetTab.close(), DOWNLOAD_INTERVAL);
  35.  
  36. if (anchors.length) {
  37. setTimeout(() => downloadNext(anchors), DOWNLOAD_INTERVAL);
  38. }
  39. }
  40.  
  41. jQuery('.torrent-list').append(
  42. `<tr style="background: none;">
  43. <td colspan="9" align="center">
  44. <a title="Download all" href class="mt-batch-download">
  45. < Download all (${fileCount}) >
  46. <br>
  47. <i class="fa fa-fw fa-magnet"></i>
  48. </a>
  49. </td>
  50. </tr>`
  51. );
  52. jQuery('.mt-batch-download').click(event => {
  53. event.preventDefault();
  54. downloadAll();
  55. });
  56.  
  57. }
  58. }
  59.  
  60. const initialize = () => {
  61. appendBatchDownloadButton();
  62. }
  63.  
  64. initialize();
  65.  
  66. })();