EromeDL

Download videos from EROME with ease, bypassing download restrictions.

当前为 2024-12-29 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         EromeDL
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Download videos from EROME with ease, bypassing download restrictions.
// @author       BLOCKCHAIN021
// @match        https://*.erome.com/*
// @grant        GM_download
// @grant        GM_xmlhttpRequest
// @icon         https://cdn.statically.io/img/i2.wp.com/whatdoesmean.net/wp-content/uploads/2023/09/icon.png
// @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();
})();