Greasy Fork is available in English.

中转罔泮栀怜

懒得描述..

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         中转罔泮栀怜
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  懒得描述..
// @author       https://greasyfork.org/zh-CN/users/158417-mo-jie
// @match        *://*.alipan.com/*
// @match        *://*.aliyundrive.com/*
// @match        *://*.quark.cn/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    //接入api
    const app_host_ali = '';
    const app_host_quark = '';

    //RPC配置
    const rpc_host = 'https://a.com';
    const rpc_port = 6800;
    const rpc_secret = 'password';
    const rpc_path = '/jsonrpc';
    const download_path = '/root/downloads';


    // 添加初始化按钮
    function addInitButton() {
        // 创建下载助手按钮
        const $button = $('<button class="pl-button-init">罔泮栀怜</button>');

        // 添加样式
        const style = document.createElement('style');
        style.textContent = `
    .pl-button-init {
        background-color: #4CAF50; /* 绿色背景 */
        border: none; /* 无边框 */
        color: white; /* 白色文字 */
        padding: 10px 20px; /* 内边距 */
        text-align: center; /* 文字居中 */
        text-decoration: none; /* 无下划线 */
        display: inline-block; /* 内联块元素 */
        font-size: 16px; /* 字体大小 */
        margin: 4px 2px; /* 外边距 */
        cursor: pointer; /* 鼠标指针 */
        border-radius: 5px; /* 圆角 */
        transition: background-color 0.3s; /* 背景色过渡 */
    }

    .pl-button-init:hover {
        background-color: #45a049; /* 悬停时的背景色 */
    }
`;
        document.head.appendChild(style);

        // 查找包含按钮的容器元素
        const addButtonToContainer = () => {
            const breadcrumbContainer = document.querySelector('.breadcrumb--iusYA.breadcrumb-wrap--Uq5Lb') || document.querySelector('.quark-breadcrumb-container');
            const quarkButtonContainer = document.querySelector('.btn-operate');
            if (breadcrumbContainer && !breadcrumbContainer.querySelector('.pl-button-init')) {
                breadcrumbContainer.insertBefore($button[0],breadcrumbContainer.firstChild);
            } else if (quarkButtonContainer && !quarkButtonContainer.querySelector('.pl-button-init')) {
                quarkButtonContainer.insertBefore($button[0], quarkButtonContainer.firstChild);
            }
        };

        // 使用 MutationObserver 监听 DOM 变化
        const observer = new MutationObserver(addButtonToContainer);
        observer.observe(document.body, { childList: true, subtree: true });

        // 初始尝试添加按钮
        addButtonToContainer();

        // 按钮点击事件处理函数
        $button.click(() => {
            // 选择所有 data-is-selected="true" 的 div 元素
            const selectedDivs = document.querySelectorAll('div[data-is-selected="true"]');
            const selectedTrs = document.querySelectorAll('tr.ant-table-row-selected');

            // 存储生成的 URL
            let urls = [];
            // 存储路径信息
            let pathInfo = [];

            // 获取路径信息
            const breadcrumbContainer = document.querySelector('.breadcrumb--iusYA.breadcrumb-wrap--Uq5Lb') || document.querySelector('.quark-breadcrumb-container');
            if (breadcrumbContainer) {
                const breadcrumb = breadcrumbContainer.querySelector('.breadcrumb--gnRPG') || breadcrumbContainer.querySelector('.quark-breadcrumb');
                if (breadcrumb) {
                    const breadcrumbItems = breadcrumb.querySelectorAll('.breadcrumb-item--j8J5H') || breadcrumb.querySelectorAll('.quark-breadcrumb-item');
                    breadcrumbItems.forEach(item => {
                        const dataLabel = item.getAttribute('data-label') || item.textContent.trim();
                        if (dataLabel) {
                            pathInfo.push(dataLabel);
                        }
                    });
                }
            }

            // 处理 Quark 的路径信息
            const quarkBreadcrumb = document.querySelector('.file-list-breadcrumb .primary');
            if (quarkBreadcrumb) {
                const quarkItems = quarkBreadcrumb.querySelectorAll('span[title]');
                quarkItems.forEach(item => {
                    const title = item.getAttribute('title');
                    if (title && title !== '全部文件') {
                        pathInfo.push(title);
                    }
                });
            }

            console.log('Path Info before filtering:', pathInfo);

            // 剔除指定项
            const itemsToRemove = ['资源库', '备份盘'];
            pathInfo = pathInfo.filter(item => !itemsToRemove.includes(item));
            console.log('Path Info after filtering:', pathInfo);

            // 拼接路径
            const paths = pathInfo.join('/');
            console.log('Paths:', paths);

            // 遍历每个选中的 div 元素
            selectedDivs.forEach(selectedDiv => {
                // 找到其下的第二个 div
                const secondDiv = selectedDiv.querySelector('div:nth-of-type(2)');

                if (secondDiv) {
                    // 找到第二个 div 下的 div,再下的 p 标签
                    const targetP = secondDiv.querySelector('div > div > p');

                    if (targetP) {
                        // 获取 p 标签的文本内容
                        let fileName = targetP.textContent.trim();

                        // 构建完整的URL
                        let full_url;
                        if (paths) {
                            full_url = `${app_host_ali}/${paths}/${encodeURIComponent(fileName)}`;
                        } else {
                            full_url = `${app_host_ali}/${encodeURIComponent(fileName)}`;
                        }

                        // 存储完整的URL
                        urls.push(full_url);
                    }
                }
            });

            // 遍历每个选中的 tr 元素
            selectedTrs.forEach(selectedTr => {
                const targetDiv = selectedTr.querySelector('td:nth-of-type(2) > div > div:nth-of-type(2) > div:nth-of-type(2)');
                if (targetDiv) {
                    let fileName = targetDiv.textContent.trim();

                    // 构建完整的URL
                    let full_url;
                    if (paths) {
                        full_url = `${app_host_quark}/${paths}/${encodeURIComponent(fileName)}`;
                    } else {
                        full_url = `${app_host_quark}/${encodeURIComponent(fileName)}`;
                    }

                    // 存储完整的URL
                    urls.push(full_url);
                }
            });

            // 创建并显示弹出窗口
            displayPopup(urls);
        });
    }

    // 创建并显示弹出窗口
    function displayPopup(urls) {
        // 创建弹出窗口的背景遮罩层
        const overlay = document.createElement('div');
        overlay.style.position = 'fixed';
        overlay.style.top = '0';
        overlay.style.left = '0';
        overlay.style.width = '100%';
        overlay.style.height = '100%';
        overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
        overlay.style.zIndex = '9999';

        // 创建弹出窗口
        const popup = document.createElement('div');
        popup.style.position = 'fixed';
        popup.style.top = '50%';
        popup.style.left = '50%';
        popup.style.transform = 'translate(-50%, -50%)';
        popup.style.backgroundColor = '#fff';
        popup.style.padding = '20px';
        popup.style.borderRadius = '8px';
        popup.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
        popup.style.maxHeight = '80%';
        popup.style.overflowY = 'auto';
        popup.style.zIndex = '10000';

        // 添加标题
        const title = document.createElement('h2');
        title.textContent = '生成的链接';
        title.style.marginTop = '0';
        popup.appendChild(title);

        // 添加链接列表
        const list = document.createElement('ul');
        urls.forEach((url, index) => {
            const listItem = document.createElement('li');
            listItem.textContent = `${index + 1}. `;
            const link = document.createElement('a');
            link.href = url;
            link.textContent = decodeURIComponent(url);
            link.target = '_blank';
            listItem.appendChild(link);
            list.appendChild(listItem);
        });
        popup.appendChild(list);

        // 添加复制所有链接按钮
        const copyButton = document.createElement('button');
        copyButton.textContent = '复制所有链接';
        copyButton.style.marginTop = '10px';
        copyButton.style.backgroundColor = '#28a745';
        copyButton.style.color = '#fff';
        copyButton.style.border = 'none';
        copyButton.style.padding = '10px';
        copyButton.style.borderRadius = '5px';
        copyButton.style.cursor = 'pointer';
        copyButton.addEventListener('click', () => {
            const textToCopy = urls.join('\n');
            navigator.clipboard.writeText(textToCopy).then(() => {
                showNotification('链接已复制到剪贴板');
            }).catch(err => {
                console.error('复制失败', err);
                showNotification('复制失败');
            });
        });
        popup.appendChild(copyButton);

        // 添加发送RPC请求按钮
        const rpcButton = document.createElement('button');
        rpcButton.textContent = '发送RPC请求';
        rpcButton.style.marginTop = '10px';
        rpcButton.style.marginLeft = '10px';
        rpcButton.style.backgroundColor = '#007bff';
        rpcButton.style.color = '#fff';
        rpcButton.style.border = 'none';
        rpcButton.style.padding = '10px';
        rpcButton.style.borderRadius = '5px';
        rpcButton.style.cursor = 'pointer';
        rpcButton.addEventListener('click', () => {
            sendRpcRequests(urls);
        });
        popup.appendChild(rpcButton);

        // 添加关闭按钮
        const closeButton = document.createElement('button');
        closeButton.textContent = '关闭';
        closeButton.style.marginTop = '10px';
        closeButton.style.marginLeft = '10px';
                closeButton.style.backgroundColor = '#dc3545';
        closeButton.style.color = '#fff';
        closeButton.style.border = 'none';
        closeButton.style.padding = '10px';
        closeButton.style.borderRadius = '5px';
        closeButton.style.cursor = 'pointer';
        closeButton.addEventListener('click', () => {
            document.body.removeChild(overlay);
        });
        popup.appendChild(closeButton);

        // 将弹出窗口和背景遮罩层添加到页面
        overlay.appendChild(popup);
        document.body.appendChild(overlay);
    }

// 发送RPC请求
    function sendRpcRequests(urls) {
        const rpcUrl = `${rpc_host}:${rpc_port}${rpc_path}`;
        const headers = {
            'Content-Type': 'application/json'
        };

        urls.forEach(url => {
            const jsonRpcData = {
                jsonrpc: '2.0',
                method: 'aria2.addUri',
                id: new Date().getTime(),
                params: [
                    `token:${rpc_secret}`,
                    [url],
                    {
                        dir: download_path
                    }
                ]
            };

            fetch(rpcUrl, {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(jsonRpcData)
            })
            .then(response => response.json())
            .then(data => {
                showNotification('RPC请求成功');
                console.log('RPC请求成功', data);
            })
            .catch(error => {
                showNotification('RPC请求失败');
                console.error('RPC请求失败', error);
            });
        });
    }

    // 显示通知
    function showNotification(message) {
        const notification = document.createElement('div');
        notification.textContent = message;
        notification.style.position = 'fixed';
        notification.style.bottom = '20px';
        notification.style.right = '20px';
        notification.style.backgroundColor = '#333';
        notification.style.color = '#fff';
        notification.style.padding = '10px';
        notification.style.borderRadius = '5px';
        notification.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
        notification.style.zIndex = '10001';

        document.body.appendChild(notification);

        setTimeout(() => {
            document.body.removeChild(notification);
        }, 3000);
    }

    // 初始化函数
    function init() {
        addInitButton();
    }

    // 等待页面加载完成后初始化脚本
    window.addEventListener('load', init);
})();