Universal Video Downloader

Enhanced video downloader with a selection feature

目前為 2025-03-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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() {};
})();