百度网盘文件直链解析助手(2025.9.9可用)

百度网盘免会员文件直链解析满速下载

// ==UserScript==
// @name         百度网盘文件直链解析助手(2025.9.9可用)
// @namespace    https://www.qyccc.com/
// @version      0.11
// @description  百度网盘免会员文件直链解析满速下载
// @author       清语尘
// @match        *://pan.baidu.com/*
// @match        *://analysis.icy6.cn/*
// @exclude      *://pan.baidu.com/aipan/search*
// @require      https://lib.baomitu.com/jquery/1.11.1/jquery.min.js
// @require      https://cdnjs.loli.net/ajax/libs/limonte-sweetalert2/11.4.4/sweetalert2.all.min.js
// @icon         https://android-artworks.25pp.com/fs08/2025/09/05/3/110_a434d925c0416fd0188b2d7fea68d7fb_con.png
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_notification
// @grant        GM_addStyle
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    GM_addStyle(`
        .swal2-popup {
            transition: all 0.3s ease-out !important;
        }
        #qyc-con iframe {
            border-radius: 8px;
        }
        .swal2-container {
            z-index: 100000 !important;
        }
    `);

    if (window.location.href.includes('/aipan/search')) {
        return;
    }

    let isDialogOpen = false;
    let hasBoundCopyEvents = false;
    let currentShareData = null;

    if (window.location.hostname === 'analysis.icy6.cn') {
        handleAnalysisSite();
    } else if (window.location.hostname.includes('baidu.com')) {
        handleBaiduNetdisk();
    }

    function handleAnalysisSite() {
        function hideSider() {
            const sider = document.querySelector('.t-layout__sider');
            const targetDiv = document.querySelectorAll('.t-layout__content .t-card.t-card--bordered');
            const pinfo = targetDiv[0].querySelectorAll('p');

            if (sider) {
                sider.style.display = 'none';
                pinfo[3].style.display = 'none';
                targetDiv[0].style.display = 'none';
                observer.disconnect();
            }
        }

        function autoFillForm() {
            const shareData = GM_getValue('baidu_share_data', null);

            if (shareData && shareData.link) {
                // 查找输入框
                const inputs = document.querySelectorAll('.t-input__inner');
                if (inputs.length > 0) {
                    // 填写分享链接
                    inputs[0].value = shareData.link;
                    const inputEvent = new Event('input', { bubbles: true });
                    inputs[0].dispatchEvent(inputEvent);

                    inputs[0].focus();

                    console.log('已自动填写分享链接: ' + shareData.link);

                    // 清除存储的数据
                    GM_setValue('baidu_share_data', null);

                    setTimeout(function(){
                        inputs[0].blur();
                    }, 300);
                }
            }
        }

        // 使用MutationObserver监听DOM变化
        const observer = new MutationObserver(function(mutations) {
            hideSider();
            autoFillForm();
        });

        observer.observe(document.body, { childList: true, subtree: true });

        // 初始执行
        hideSider();
        autoFillForm();
    }

    function handleBaiduNetdisk() {
        if (typeof $ === 'undefined') {
            setTimeout(handleBaiduNetdisk, 100);
            return;
        }

        $(document).ready(function() {
            setupShareListener();
        });
    }

    function setupShareListener() {
        let shareData = {
            link: '',
            code: ''
        };

        // 使用事件委托绑定复制按钮
        function bindCopyButtonEvents() {
            if (hasBoundCopyEvents) return;

            // 使用事件委托处理复制按钮点击
            document.addEventListener('click', function(e) {
                const target = e.target;
                const copyButton = target.closest('.u-button.wp-share-file__link-create-ubtn');

                if (copyButton && copyButton.textContent.includes('复制中')) {
                    setTimeout(() => {
                        if(copyButton.textContent.includes('复制链接')){
                            navigator.clipboard.readText().then(text => {
                                if (text.includes('pan.baidu.com')) {
                                    processShareText(text);
                                }
                            }).catch(err => {
                                console.log('无法读取剪贴板:', err);
                                extractShareInfoFromPage();
                            });
                        }else{
                            Swal.fire({
                                position: 'center',
                                icon: 'error',
                                title: '程序运行错误',
                                text: '请重试一次!持续错误可扫码联系作者',
                                imageUrl: 'https://www.pupp.top/gzh.jpg',
                                imageWidth: 200,
                                imageAlt: '微信公众号【干货老周】',
                                showConfirmButton: true,
                                timer: 5000,
                                timerProgressBar: true
                            });
                        }
                    }, 1500);
                }
            });

            hasBoundCopyEvents = true;
        }

        // 使用防抖函数避免频繁触发
        const debounce = (func, wait) => {
            let timeout;
            return function executedFunction(...args) {
                const later = () => {
                    clearTimeout(timeout);
                    func(...args);
                };
                clearTimeout(timeout);
                timeout = setTimeout(later, wait);
            };
        };

        // 处理分享弹窗的函数
        const handleShareDialog = debounce(function(shareDialog) {
            if (!shareDialog) return;

            findShareInfo(shareDialog);
            bindCopyButtonEvents();
        }, 300);

        const observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.addedNodes.length) {
                    const shareDialog = document.querySelector('.wp-s-share-hoc__dialog');
                    if (shareDialog) {
                        handleShareDialog(shareDialog);
                    }
                }
            });
        });

        observer.observe(document.body, { childList: true, subtree: true });

        // 从页面元素提取分享信息
        function extractShareInfoFromPage() {
            // 查找包含分享链接的元素
            const linkElements = document.querySelectorAll('[class*="link"], [class*="url"], [class*="share"]');
            for (let el of linkElements) {
                if (el.textContent.includes('pan.baidu.com')) {
                    processShareText(el.textContent);
                    return;
                }
            }

            // 查找提取码
            const codeElements = document.querySelectorAll('[class*="code"], [class*="pwd"], [class*="password"]');
            for (let el of codeElements) {
                const codeMatch = el.textContent.match(/([a-zA-Z0-9]{4})/);
                if (codeMatch && codeMatch[1]) {
                    shareData.code = codeMatch[1];
                    GM_setValue('baidu_share_data', shareData);
                    break;
                }
            }
        }

        // 处理分享文本
        function processShareText(text) {
            // 检查是否已经处理过相同的分享数据
            const linkMatch = text.match(/https?:\/\/pan\.baidu\.com\/s\/[^\s]+/);
            if (!linkMatch) return;

            const newLink = linkMatch[0];

            // 如果是相同的分享链接且已经处理过,则不再处理
            if (currentShareData && currentShareData.link === newLink) {
                return;
            }

            shareData.link = newLink;

            // 提取提取码
            const codeMatch = text.match(/提取码[::]\s*([a-zA-Z0-9]{4})/);
            if (codeMatch && codeMatch[1]) {
                shareData.code = codeMatch[1];
            } else {
                const codeMatch2 = text.match(/([a-zA-Z0-9]{4})/);
                if (codeMatch2 && codeMatch2[1]) {
                    shareData.code = codeMatch2[1];
                }
            }

            // 存储当前分享数据
            currentShareData = {...shareData};
            GM_setValue('baidu_share_data', shareData);

            const shareDialog = document.querySelector('.wp-s-share-hoc__dialog');
            if (shareDialog) {
                const closeButton = shareDialog.querySelector('.u-dialog__headerbtn');
                if (closeButton) {
                    setTimeout(function(){
                        closeButton.click();
                    }, 500);
                }
            }

            if (isDialogOpen) {
                Swal.close();
            }

            Swal.fire({
                position: 'top-end',
                icon: 'success',
                title: '已捕获分享链接!',
                text: '将自动打开解析页面并填充...',
                showConfirmButton: false,
                timer: 3000,
                timerProgressBar: true,
                didClose: () => {
                    isDialogOpen = false;
                }
            });
            isDialogOpen = true;

            setTimeout(function(){
                Swal.close();
                Swal.fire({
                    title: '<strong>文件直链解析助手</strong>',
                    footer: '<div style="text-align:center">感谢公益解析平台提供的服务,本脚本仅提供集成便于使用<br>详细使用说明:微信公众号关注【干货老周】发送“百度网盘解析”获取</div>',
                    width: 1024,
                    html: '<div id="qyc-con" style="position: relative; padding: 30% 45%;"><iframe style="position: absolute; width: 100%; height: 100%; left: 0; top: 0;" src="https://analysis.icy6.cn/user/parse" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" allowtransparency> </iframe> </div>',
                    showCloseButton: true,
                    showConfirmButton: false,
                    showCancelButton: false,
                    allowOutsideClick: false,
                    didOpen: () => {
                        isDialogOpen = true;
                    },
                    willClose: () => {
                        isDialogOpen = false;
                        currentShareData = null;
                    }
                });
            }, 3500);

            console.log('已捕获分享链接: ' + shareData.link);
            if (shareData.code) {
                console.log('已捕获提取码: ' + shareData.code);
            }
        }

        // 在分享弹窗中查找分享信息
        function findShareInfo(dialog) {
            // 查找所有文本内容
            const textContent = dialog.textContent;
            if (textContent.includes('pan.baidu.com')) {
                processShareText(textContent);
            }

            // 查找特定的输入框或显示区域
            const inputs = dialog.querySelectorAll('input, textarea, [class*="link"], [class*="url"]');
            for (let input of inputs) {
                if (input.value && input.value.includes('pan.baidu.com')) {
                    processShareText(input.value);
                    break;
                } else if (input.textContent && input.textContent.includes('pan.baidu.com')) {
                    processShareText(input.textContent);
                    break;
                }
            }
        }

        setTimeout(() => {
            if (!isDialogOpen) {
                Swal.fire({
                    position: 'center',
                    icon: 'success',
                    title: '直链解析助手初始化成功!',
                    html: '请正常分享一个或多个要下载的文件或文件夹,系统获取到分享链接将自动运行下一步!',
                    footer: '<div style="text-align:center;font-size:small">详细使用说明:扫码关注微信公众号【干货老周】发送“百度网盘解析”获取</div>',
                    imageUrl: 'https://www.pupp.top/gzh.jpg',
                    imageWidth: 200,
                    imageAlt: '微信公众号【干货老周】',
                    showConfirmButton: true,
                    timer: 10000,
                    timerProgressBar: true
                });
            }
        }, 1000);
    }
})();