Universal Video Downloader

Enhanced video downloader with a selection feature

当前为 2025-03-06 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Universal Video Downloader
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Enhanced video downloader with a selection feature
// @author       usercromix
// @match        
// @grant        none

// ==/UserScript==

(function() {
    'use strict';

    // Create UI container
    const uiContainer = document.createElement('div');
    uiContainer.id = 'video-downloader-ui';
    uiContainer.style.cssText = `
        position: fixed;
        z-index: 9999;
        background: linear-gradient(135deg, #2b2d42, #8d99ae);
        padding: 15px;
        border-radius: 10px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
        cursor: move;
        user-select: none;
        top: 20px;
        right: 20px;
        font-family: Arial, sans-serif;
        transition: all 0.3s ease;
    `;

    // Create header
    const header = document.createElement('div');
    header.textContent = 'Video Downloader';
    header.style.cssText = `
        color: #edf2f4;
        font-size: 14px;
        font-weight: bold;
        margin-bottom: 10px;
        text-align: center;
    `;

    // Create button container
    const buttonContainer = document.createElement('div');
    buttonContainer.style.cssText = `
        display: flex;
        flex-direction: column;
        gap: 10px;
    `;

    // Create Download button
    const downloadButton = document.createElement('button');
    downloadButton.textContent = 'Download Video';
    downloadButton.style.cssText = `
        background: linear-gradient(45deg, #ef233c, #d90429);
        color: white;
        border: none;
        padding: 8px 16px;
        border-radius: 5px;
        cursor: pointer;
        transition: transform 0.2s ease;
    `;

    // Create Select Video button
    const selectButton = document.createElement('button');
    selectButton.textContent = 'Select Video';
    selectButton.style.cssText = `
        background: linear-gradient(45deg, #023e8a, #0077b6);
        color: white;
        border: none;
        padding: 8px 16px;
        border-radius: 5px;
        cursor: pointer;
        transition: transform 0.2s ease;
    `;

    // Button hover effects
    [downloadButton, selectButton].forEach(button => {
        button.addEventListener('mouseover', () => button.style.transform = 'scale(1.05)');
        button.addEventListener('mouseout', () => button.style.transform = 'scale(1)');
    });

    // Append elements
    buttonContainer.appendChild(downloadButton);
    buttonContainer.appendChild(selectButton);
    uiContainer.appendChild(header);
    uiContainer.appendChild(buttonContainer);
    document.body.appendChild(uiContainer);

    // Make UI draggable
    let isDragging = false;
    let currentX = window.innerWidth - uiContainer.offsetWidth - 20;
    let currentY = 20;

    header.addEventListener('mousedown', (e) => {
        isDragging = true;
        const rect = uiContainer.getBoundingClientRect();
        initialX = e.clientX - rect.left;
        initialY = e.clientY - rect.top;
    });

    let initialX, initialY;
    document.addEventListener('mousemove', (e) => {
        if (isDragging) {
            e.preventDefault();
            currentX = e.clientX - initialX;
            currentY = e.clientY - initialY;
            uiContainer.style.left = currentX + 'px';
            uiContainer.style.top = currentY + 'px';
            uiContainer.style.right = 'auto';
        }
    });

    document.addEventListener('mouseup', () => {
        isDragging = false;
    });

    // Video handling functions
    function downloadVideo(videoUrl) {
        if (!videoUrl) {
            alert('No video selected or detected!');
            return;
        }
        const downloadLink = document.createElement('a');
        downloadLink.href = videoUrl;
        downloadLink.download = `video_${new Date().getTime()}.mp4`;
        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);
        alert('Video download started!');
    }

    function detectVideo() {
        const videos = document.getElementsByTagName('video');
        if (videos.length > 0) {
            const video = videos[0];
            return video.src || video.currentSrc || 
                   (video.getElementsByTagName('source')[0]?.src);
        }
        
        const pageLinks = Array.from(document.getElementsByTagName('a'));
        const videoExtensions = ['.mp4', '.webm', '.mkv', '.avi', '.mov'];
        const videoLink = pageLinks.find(link => 
            videoExtensions.some(ext => link.href.toLowerCase().endsWith(ext))
        );
        return videoLink?.href;
    }

    // Download button handler
    downloadButton.addEventListener('click', () => {
        const videoUrl = detectVideo();
        downloadVideo(videoUrl);
    });

    // Video selection feature
    let isSelecting = false;
    selectButton.addEventListener('click', () => {
        if (!isSelecting) {
            isSelecting = true;
            selectButton.textContent = 'Click a Video';
            document.body.style.cursor = 'crosshair';
            
            const videoClickHandler = (e) => {
                const video = e.target.closest('video') || 
                            e.target.closest('a[href*=".mp4"]') || 
                            e.target.closest('a[href*=".webm"]');
                
                if (video) {
                    e.preventDefault();
                    const videoUrl = video.src || video.currentSrc || video.href;
                    downloadVideo(videoUrl);
                    cleanupSelection();
                }
            };

            const cleanupSelection = () => {
                isSelecting = false;
                selectButton.textContent = 'Select Video';
                document.body.style.cursor = 'default';
                document.removeEventListener('click', videoClickHandler);
            };

            document.addEventListener('click', videoClickHandler, { once: true });
            setTimeout(cleanupSelection, 10000); // 10-second timeout
        }
    });

    // Anti-detection measures
    Object.defineProperty(window, 'videoDownloader', {
        value: undefined,
        writable: false,
        configurable: false
    });
    console.log = function() {};
})();