Greasy Fork

Greasy Fork is available in English.

FindDownloadLink

侦测页面中的磁力链接&&下载地址并生成到按钮中

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         FindDownloadLink
// @namespace    https://lilopusic.github.io/
// @version      0.1
// @description  侦测页面中的磁力链接&&下载地址并生成到按钮中
// @author       hnayan
// @grant        GM_addStyle
// @require      https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js
// @require      https://cdn.bootcss.com/clipboard.js/2.0.1/clipboard.min.js
// @include      http://*
// @include      https://*
// ==/UserScript==

(function () {
    addStyle();
    new ClipboardJS('.getAll');
    class RenderButton {
        constructor($, $dom, $a) {
            this.$dom = $dom;
            this.$a = $a;
            this.$ = $;
            this.map = new Map();
        }
        push(name, href) {
            if (!this.map.has(name)) {
                this.map.set(name, []);
            }
            this.map.get(name).push(href);
        }
        render() {
            for (let name of this.map.keys()) {
                this.appendButton(name, this.map.get(name));
            }
        }
        appendButton(name, list) {
            if (list.length !== 0) {
                this.$dom.append(`<button data-clipboard-text="${list.join('\n')}"  title="Total: ${list.length}" class="getAll" id="get${name}">Get All ${name}.</button>`);
            }
        }
        init() {
            let $ = this.$;
            $('body').append($container);
            for (let i = 0; i < this.$a.length; i++) {
                let href = $($a[i]).attr('href');
                if (href.startsWith('ed2k')) {
                    this.push('Ed2k', $($a[i]).attr('href'));
                }
                if (href.startsWith('magnet')) {
                    this.push('Magnet', $($a[i]).attr('href'));
                }
                if (href.startsWith('thunder')) {
                    this.push('Thunder', $($a[i]).attr('href'));
                }
                if (href.endsWith('exe')) {
                    this.push('Exe', $($a[i]).attr('href'));
                }
                if (href.endsWith('zip') || href.endsWith('rar')) {
                    this.push('Zip', $($a[i]).attr('href'));
                }
            }
        }
    }
    const $a = $('a[href]');
    const $container = $('<div id="getAllPanel" style="position: fixed;right: -50px;top: 100px;z-index: 9999"></div>');
    const renderButton = new RenderButton($, $container, $a);
    renderButton.init();
    renderButton.render();

    function addStyle(){
        GM_addStyle('.getAll {right:0px;transition: right .5s;position:relative;min-width:100%;margin:5px 0;background-color:white;display: block;padding:10px 15px;border: 1px solid #eee;border-bottom-color: #ddd;-webkit-border-radius: 3px;-webkit-box-shadow: 0 1px 3px #eee;-moz-border-radius: 3px;-moz-box-shadow: 0 1px 3px #eee;border-radius: 100px 0 0 100px;outline: none;cursor: pointer;}');
        GM_addStyle('.getAll:hover {right: 50px;}');
    }
})();