EromeDL

Download videos from EROME with ease, bypassing download restrictions.

目前為 2024-12-29 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         EromeDL
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  Download videos from EROME with ease, bypassing download restrictions.
// @author       BLOCKCHAIN021
// @match        https://*.erome.com/*
// @grant        GM_download
// @grant        GM_xmlhttpRequest
// @license      MIT
// ==/UserScript==


(function () {
    'use strict';

    // Helper function to create styled buttons
    function createButton(text, onClick) {
        const button = document.createElement('button');
        button.textContent = text;
        button.style.position = 'absolute';
        button.style.bottom = '10px';
        button.style.right = '10px';
        button.style.zIndex = '1000';
        button.style.padding = '12px 18px';
        button.style.backgroundColor = '#28a745';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '8px';
        button.style.fontSize = '16px';
        button.style.cursor = 'pointer';
        button.style.boxShadow = '0px 5px 10px rgba(0, 0, 0, 0.2)';
        button.addEventListener('mouseover', () => {
            button.style.backgroundColor = '#218838';
        });
        button.addEventListener('mouseout', () => {
            button.style.backgroundColor = '#28a745';
        });
        button.onclick = onClick;
        return button;
    }

    // Function to add download buttons to videos
    function addDownloadButtons() {
        const videos = document.querySelectorAll('video');
        videos.forEach(video => {
            if (!video.parentNode.querySelector('.download-button')) {
                const downloadButton = createButton('Download', () => downloadVideo(video));
                downloadButton.className = 'download-button';
                video.parentNode.style.position = 'relative'; // Ensure parent has relative position for button placement
                video.parentNode.appendChild(downloadButton);
            }
        });
    }

    // Function to download video
    function downloadVideo(video) {
        let videoUrl = '';

        // Attempt to get URL from <source> tag
        const sourceTag = video.querySelector('source');
        if (sourceTag && sourceTag.src) {
            videoUrl = sourceTag.src;
        }

        // Fallback: Try direct video attributes
        if (!videoUrl) {
            videoUrl = video.src || video.getAttribute('data-src') || '';
        }

        // Advanced Fallback: Attempt to fetch video URL via GM_xmlhttpRequest
        if (!videoUrl) {
            const videoId = video.id;
            const config = video.getAttribute('data-setup');
            if (config) {
                try {
                    const parsedConfig = JSON.parse(config.replace(/&quot;/g, '"'));
                    if (parsedConfig.poster) {
                        videoUrl = parsedConfig.poster.replace(/\.jpg$/, '_720p.mp4');
                    }
                } catch (e) {
                    console.error('Failed to parse video config:', e);
                }
            }
        }

        // Log the URL to the console for debugging
        console.log('Video URL:', videoUrl);

        // If URL is found, attempt download
        if (videoUrl) {
            openVideoInNewTab(videoUrl);
        } else {
            alert('Could not locate the video URL. Please ensure the video is loaded.');
        }
    }

    // Function to open video in a new tab with styling
    function openVideoInNewTab(videoUrl) {
        const newWindow = window.open('', '_blank');
        newWindow.document.write(`
            <html>
                <head>
                    <title>Video</title>
                    <style>
                        body {
                            margin: 0;
                            background-color: black;
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            height: 100vh;
                        }
                        video {
                            max-width: 90%;
                            max-height: 90%;
                            object-fit: contain;
                        }
                    </style>
                </head>
                <body>
                    <video controls autoplay>
                        <source src="${videoUrl}" type="video/mp4">
                        Your browser does not support the video tag.
                    </video>
                </body>
            </html>
        `);
    }

    // Observe DOM changes to dynamically add buttons
    const observer = new MutationObserver(() => addDownloadButtons());
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial call to add buttons
    addDownloadButtons();
})();