Greasy Fork is available in English.

迅雷电影天堂磁力链批量下载

迅雷电影天堂 | 详情页 | 磁力链列表上方标题行新增【批量下载磁力链】超链接

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         迅雷电影天堂磁力链批量下载
// @namespace    http://tampermonkey.net/
// @version      2024-09-29
// @description  迅雷电影天堂 | 详情页 | 磁力链列表上方标题行新增【批量下载磁力链】超链接
// @author       JoyofFire
// @match        https://www.xl720.com/thunder/*.html
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const selectors = {
        title: ".entry-content > h2:last-of-type",
        anchor: "#zdownload .down_btn_cl a",
    };
    const values = {
        magnet_protocal: "magnet:",
        dl_btn_text: "> 批量下载磁力链 <",
        new_tab: "_blank",
    };

    const $ = (querySelectorAll) => (x) => [...querySelectorAll(x)];
    const dom$ = $(document.querySelectorAll.bind(document));
    const el$ = (el) => $(el.document.querySelectorAll.bind(el));

    const anchor_to_link = (a) => a.href;
    const is_magnet = (x) => `${x}`.startsWith(values.magnet_protocal);
    const anchors_to_links = (xs) => xs.map(anchor_to_link).filter(is_magnet);
    const text_to_blob = (x) => new Blob([x], { type: "text/plain" });

    const maybe_title = () => new Promise((resolve, reject) => {
        const matches = dom$(selectors.title);
        const _return = matches.length > 0 ? resolve : reject;
        _return(matches.at(-1));
    });

    const append_href_to_title = (url) => (title) => {
        const a = document.createElement("a");
        a.target = values.new_tab;
        a.textContent = values.dl_btn_text;
        a.href = url;
        title.append(a);
        return { title, url };
    };

    const handle_error = (error) => {
        if (!error) {
            alert("找不到标题行!无法添加按钮!");
            return;
        }
        console.error(error);
    };

    const main = () => {
        const anchors = dom$(selectors.anchor);
        const links = anchors_to_links(anchors);
        const links_text = links.join("\n");
        const text_blob = text_to_blob(links_text);
        const text_url = URL.createObjectURL(text_blob);

        maybe_title()
            .then(append_href_to_title(text_url))
            .then(console.info.bind(console))
            .catch(handle_error);
    };

    main();
})();