[nyaa.si] Batch Download

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

目前為 2020-03-01 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         [nyaa.si] Batch Download
// @description  Allows batch download of all displayed results in one single click.
// @author       MetalTxus
// @version      1.1.0

// @include      /^https?:\/\/\S*nyaa.si\S*/
// @require      http://code.jquery.com/jquery-3.2.1.min.js
// @icon         https://avatars3.githubusercontent.com/u/28658394?s=44
// @namespace    https://greasyfork.org/users/8682
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(() => {
  'use strict';

  const DOWNLOAD_INTERVAL = 150;

  const jQuery = window.jQuery;

  const magnets = jQuery('a[href*="magnet:"]');

  const appendBatchDownloadButton = () => {
    const fileCount = magnets.length;
    if (fileCount) {
      const downloadAll = () => {
        downloadNext(magnets.toArray());
      }

      const downloadNext = (anchors) => {
        const anchor = anchors.pop();
        const url = anchor.href.split('&dn=')[0];
        const magnetTab = window.open(url);
        setTimeout(() => magnetTab.close(), DOWNLOAD_INTERVAL);

        if (anchors.length) {
          setTimeout(() => downloadNext(anchors), DOWNLOAD_INTERVAL);
        }
      }

      jQuery('.torrent-list').append(
        `<tr style="background: none;">
           <td colspan="9" align="center">
             <a title="Download all" href class="mt-batch-download">
               < Download all (${fileCount}) >
               <br>
               <i class="fa fa-fw fa-magnet"></i>
             </a>
           </td>
         </tr>`
      );
      jQuery('.mt-batch-download').click(event => {
        event.preventDefault();
        downloadAll();
      });

    }
  }

  const initialize = () => {
    appendBatchDownloadButton();
  }

  initialize();

})();