[nyaa.si] Batch Download

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

目前为 2017-06-06 提交的版本。查看 最新版本

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

// @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=48
// @namespace    https://gf.qytechs.cn/users/8682
// ==/UserScript==

(function() {
    'use strict';

    var DEBUGGING_ENABLED = false,
        MAGNET_SELECTOR = 'a[href*="/download/"]',
        DOWNLOADS_SELECTOR = '.mt-hidden-downloads',
        DOWNLOAD_INTERVAL = 1000;

    var fileCount = 0;

    function appendBatchDownloadButton () {
        fileCount = $(MAGNET_SELECTOR).length;

        if (fileCount) {
            $('.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>');

            $('.mt-batch-download').click(downloadAll);

            $('body').append($('<div class="mt-hidden-downloads">').hide());
        }
    }

    function downloadAll(event) {
        event.preventDefault();

        $(DOWNLOADS_SELECTOR).html('');

        $(MAGNET_SELECTOR).each(function (i, downloadLink) {
            setTimeout(function () {
                var url = downloadLink.href;
                downloadSingle(url);

                if (DEBUGGING_ENABLED) {
                    var label = $(downloadLink).parents('tr').find('a[href^="/view/"]').eq(0).text();
                    console.debug('[nyaa.si] Batch Download: Downloading torrent ' + (i + 1) + '/' + fileCount + ' ("' + label + '", ' + url + ')');
                }

            }, i * DOWNLOAD_INTERVAL);
        });
    }

    function downloadSingle (url) {
        $(DOWNLOADS_SELECTOR).append($('<iframe>').attr('src', url));
    }

    function initialize () {
        appendBatchDownloadButton();
    }

    initialize();


})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址