腾讯视频vip解析 - 带顶部日志

在腾讯视频页面顶部显示日志面板,用于调试和信息展示

当前为 2025-08-04 提交的版本,查看 最新版本

// ==UserScript==
// @name         腾讯视频vip解析 - 带顶部日志
// @namespace    https://jixiejidiguan.top/A2zml/
// @version      2025-08-04
// @description  在腾讯视频页面顶部显示日志面板,用于调试和信息展示
// @author       jixiejidiguan.top
// @match        https://v.qq.com/x/cover/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=qq.com
// @grant        none
// @license      MT
// ==/UserScript==

(function() {
    'use strict';
const videoParsers = [
    {
        id: 'parser1',
        name: '解析接口 1',
        url: 'https://jx.playerjy.com/?ads=0&url='
    },
    {
        id: 'parser2',
        name: '解析接口 2',
        url: 'https://jx.xmflv.com/?url='
    },
    {
        id: 'parser3',
        name: '解析接口 3',
        url: 'https://z1.190000000007.top/?jx='
    },
    {
        id: 'parser4',
        name: '解析接口 4',
        url: 'https://jx.dmflv.cc/?url='
    },
    {
        id: 'parser5',
        name: '解析接口 5',
        url: 'https://www.yemu.xyz/?url='
    },
    {
        id: 'parser6',
        name: '解析接口 6',
        url: 'https://jx.nnxv.cn/tv.php?url='
    }
];

    // 防止重复注入
    function isAlreadyInjected(id) {
        return document.getElementById(id) !== null;
    }

    // 创建顶部日志面板 & 全局 logToPage 方法
    function setupLogPanel() {
        if (isAlreadyInjected('tampermonkey-log-panel')) {
            // 如果已存在,获取现有日志元素
            const log = document.getElementById('tampermonkey-log-content');
            return log;
        }

        const panel = document.createElement('div');
        panel.id = 'tampermonkey-log-panel';
        panel.style.cssText = `
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            background: #1e1e1e;
            color: #fff;
            z-index: 99999;
            padding: 10px;
            font-family: monospace;
            font-size: 14px;
            border-bottom: 2px solid #007acc;
            max-height: 200px;
            overflow-y: auto;
        `;

        const title = document.createElement('div');
        title.textContent = '🔧 TamperMonkey 脚本日志';
        title.style.cssText = `
            font-weight: bold;
            margin-bottom: 8px;
            color: #00d4ff;
        `;
        panel.appendChild(title);

        const log = document.createElement('div');
        log.id = 'tampermonkey-log-content';
        log.style.cssText = `
            white-space: pre-wrap;
            word-break: break-word;
            line-height: 1.4;
        `;
        panel.appendChild(log);

        const container = document.querySelector('.container-main');
        if (container) {
            container.appendChild(panel);
        } else {
            document.body.prepend(panel); // 备选方案
        }

        // 全局方法:打印日志到页面
        window.logToPage = function(msg, type = 'info') {
            if (!log) return;
            const time = new Date().toLocaleTimeString();
            const prefix = {
                error: '[❌ ERROR]',
                warn:  '[⚠️ WARN]',
                info:  '[ℹ️ INFO]',
                log:   '[💬 LOG]'
            }[type] || '[💬 LOG]';
            log.textContent += `${time} ${prefix} ${msg}\n`;
            log.scrollTop = log.scrollHeight;
        };

        return log; // 返回日志元素
    }

    // 创建一个竖排按钮,点击弹出模态框
    function setupToolbarButton() {
        if (isAlreadyInjected('custom-popup-button')) return;

        const btnContainer = document.createElement('div');
        btnContainer.id = 'custom-popup-button';
        btnContainer.style.cssText = `
            position: fixed;
            top: 50%;
            left: 20px;
            transform: translateY(-50%);
            z-index: 99999;
        `;

        const btn = document.createElement('button');
        btn.textContent = '🔧 打开弹窗';
        btn.style.cssText = `
            writing-mode: vertical-rl;
            text-orientation: mixed;
            padding: 12px 8px;
            background: #1976d2;
            color: white;
            border: none;
            border-radius: 4px;
            font-weight: bold;
            cursor: pointer;
            box-shadow: 0 2px 6px rgba(0,0,0,0.2);
            transition: background 0.2s;
            font-size: 14px;
        `;

        btn.onmouseover = () => btn.style.background = '#1565c0';
        btn.onmouseout = () => btn.style.background = '#1976d2';
        btn.onclick = showPopupModal;

        btnContainer.appendChild(btn);
        document.body.appendChild(btnContainer);

        window.logToPage('🔧 工具按钮已添加', 'info');
    }

    // 创建视频解析功能区域(包含输入框和按钮列表)
    function createVideoParserSection() {
        const parserContainer = document.createElement('div');
        parserContainer.style.cssText = `
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        `;

        // 标题和输入框
        parserContainer.innerHTML = `
            <h4 style="margin: 0 0 12px 0; color: #333;">视频解析</h4>
            <p style="margin: 0 0 10px 0; font-size: 14px; color: #666;">
                输入视频URL并选择解析接口
            </p>
            <div style="margin-bottom: 15px;">
                <input type="text" id="video-url-input" placeholder="请输入视频地址"
                    style="color: #000;width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px;" />
            </div>
            <div id="parser-buttons" style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;">
                <!-- 按钮会通过JS动态生成 -->
            </div>
        `;

        // 获取按钮容器
        const buttonsContainer = parserContainer.querySelector('#parser-buttons');

        // 动态生成解析按钮
        videoParsers.forEach(parser => {
            const button = document.createElement('button');
            button.id = parser.id;
            button.textContent = parser.name;
            button.style.cssText = `
                padding: 8px 12px;
                background: #1976d2;
                color: white;
                border: none;
                border-radius: 4px;
                cursor: pointer;
                transition: background 0.2s;
                text-align: center;
            `;

            // 鼠标悬停效果
            button.onmouseover = () => button.style.background = '#1565c0';
            button.onmouseout = () => button.style.background = '#1976d2';

            // 点击事件 - 使用当前解析接口解析视频
            button.onclick = () => {
                // 获取视频URL(优先使用输入框内容,否则使用当前页面URL)
                const videoInput = document.getElementById('video-url-input');
                const currentUrl = window.location.href;
                const videoUrl = videoInput.value.trim() || currentUrl;

                if (videoUrl) {
                    // 1. 关闭弹窗
                    const overlay = document.getElementById('custom-modal-overlay');
                    if (overlay) {
                        overlay.remove();
                    }

                    // 2. 清除已有的视频容器(避免重复)
                    const existingVideoContainer = document.getElementById('video-player-container');
                    if (existingVideoContainer) {
                        existingVideoContainer.remove();
                    }

                    // 3. 构建完整的解析URL
                    const fullUrl = `${parser.url}${encodeURIComponent(videoUrl)}`;

                    // 4. 创建新的视频容器
                    const videoContainer = document.createElement('div');
                    videoContainer.id = 'video-player-container';
                    videoContainer.style.cssText = `
                        position: relative;
                        width: 100%;
                        padding-top: 56.25%; /* 16:9比例 */
                        margin-top: 20px;
                    `;

                    // 5. 添加iframe视频播放器
                    videoContainer.innerHTML = `
                        <iframe src="${fullUrl}"
                            allowfullscreen
                            frameborder="0"
                            style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #000;"></iframe>
                    `;

                    // 6. 添加到页面容器
                    const container = document.querySelector('.container-main__wrapper');
                    const containerleft = document.querySelector('.container-main__left');
                    if (containerleft) {
                    containerleft.remove();
                    }
                    //
                    if (container) {
                        container.appendChild(videoContainer);

                        // 7. 记录日志
                        if (window.logToPage) {
                            window.logToPage(`使用${parser.name}解析视频: ${videoUrl}`, 'info');
                        }
                    } else {
                        console.error('未找到.container-main容器');
                        if (window.logToPage) {
                            window.logToPage('未找到视频容器,无法播放视频', 'error');
                        }
                    }
                } else {
                    alert('请输入视频地址');
                }
            };

            buttonsContainer.appendChild(button);
        });

        return parserContainer;
    }

    // 弹出模态框
    function showPopupModal() {
        // 如果已有弹窗则关闭
        const existingOverlay = document.getElementById('custom-modal-overlay');
        if (existingOverlay) {
            existingOverlay.remove();
            return;
        }

        const overlay = document.createElement('div');
        overlay.id = 'custom-modal-overlay';
        overlay.style.cssText = `
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.5);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 100000;
        `;

        const modal = document.createElement('div');
        modal.style.cssText = `
            background: white;
            padding: 24px;
            border-radius: 8px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.3);
            min-width: 400px;
            max-width: 500px;
            font-family: sans-serif;
        `;

        modal.innerHTML = `
            <h3 style="margin: 0 0 16px 0; color: #000;">🔧 视频解析工具</h3>
            <p style="margin: 0 0 20px 0; color: #666; line-height: 1.5;">
                请输入需要解析的视频地址,然后选择一个解析接口
            </p>
            <button id="close-modal-btn" style="color: #000;
                background: #f0f0f0;
                border: 1px solid #ccc;
                padding: 8px 16px;
                border-radius: 4px;
                cursor: pointer;
                margin-top: 15px;
            ">关闭</button>
        `;

        // 创建并添加视频解析区域
        const parserSection = createVideoParserSection();
        // 将解析区域添加到关闭按钮前面
        modal.insertBefore(parserSection, modal.querySelector('#close-modal-btn'));

        overlay.appendChild(modal);
        document.body.appendChild(overlay);

        // 关闭按钮事件
        modal.querySelector('#close-modal-btn').onclick = () => overlay.remove();

        // 点击背景关闭
        overlay.onclick = (e) => {
            if (e.target === overlay) overlay.remove();
        };

        if (window.logToPage) {
            window.logToPage('🔧 视频解析工具已打开', 'info');
        }
    }

    // 页面加载完成后初始化
    function init() {
        // 先确保日志面板已设置好
        const logElement = setupLogPanel();
        if (logElement) {
            window.logToPage('🚀 脚本启动初始化...', 'info');
            setupToolbarButton();
            window.logToPage('✅ 脚本初始化完成', 'info');

            // 5秒后隐藏日志面板
            setTimeout(() => {
                const logPanel = document.getElementById('tampermonkey-log-panel');
                if (logPanel) {
                    logPanel.style.display = "none";
                    window.logToPage('日志面板已隐藏(5秒自动隐藏)', 'info');
                }
            }, 5000);
        } else {
            console.error('日志面板初始化失败');
        }
    }

    // 确保页面加载完成后执行初始化
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();

QingJ © 2025

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