美剧天堂复制下载地址

给美剧天堂的 `复制下载地址` 按钮添加点击事件

目前为 2019-02-05 提交的版本。查看 最新版本

// ==UserScript==
// @name         美剧天堂复制下载地址
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  给美剧天堂的 `复制下载地址` 按钮添加点击事件
// @author       Chen
// @match        https://www.meijutt.com/content/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    const copyButton = document.getElementById("copy");
    copyButton.onclick = function () {
        const currentDisplayTabList = Array.prototype.filter.call(document.getElementsByClassName("tabs-list"), function (element) {
            return element.style.display != "none";
        });
        try {
            const currentTab = currentDisplayTabList[0];
            const lines = currentTab.getElementsByClassName("down_list")[0].getElementsByTagName("ul")[0].getElementsByTagName("li");
            const downloadUrls = [];
            Array.prototype.forEach.call(lines, function (line) {
                const checkBox = line.getElementsByTagName("input")[0];
                if (checkBox.checked) {
                    downloadUrls.push(checkBox.value);
                }
            })
            const urlsInOne = downloadUrls.join("\r\n");
            copyToClipboard(urlsInOne);
        } catch (error) {
            console.log("出错了");
        }
    }
})();

function copyToClipboard(value) {
    const textarea = document.createElement('textarea');
    textarea.readOnly = "true"
    textarea.value = value;
    document.body.appendChild(textarea);
    textarea.select();
    if (document.execCommand('copy')) {
        alert('复制成功');
    } else {
        alert("复制失败,请打开开发者工具手动复制!");
        console.log(textarea.value);
    }
    document.body.removeChild(textarea);
}

QingJ © 2025

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