Bouton Téléchargement Multi-Sites (Y2Mate, SaveTheVideo)

Ajoute des boutons pour télécharger des vidéos via Y2Mate (version française) et SaveTheVideo (pour Twitter), avec une option pour les masquer via un raccourci clavier

当前为 2025-01-31 提交的版本,查看 最新版本

// ==UserScript==
// @name         Bouton Téléchargement Multi-Sites (Y2Mate, SaveTheVideo)
// @namespace    https://gf.qytechs.cn/
// @version      1.4
// @description  Ajoute des boutons pour télécharger des vidéos via Y2Mate (version française) et SaveTheVideo (pour Twitter), avec une option pour les masquer via un raccourci clavier
// @author       Lakfu Sama
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let isButtonVisible = true;

    function addDownloadButtons() {
        const videos = document.querySelectorAll('video');
        if (videos.length === 0) return;

        videos.forEach(video => {
            if (video.dataset.hasDownloadButtons) return;
            video.dataset.hasDownloadButtons = true;

            const container = document.createElement('div');
            container.style.position = 'absolute';
            container.style.top = '10px';
            container.style.right = '10px';
            container.style.zIndex = '1000';
            container.style.display = 'flex';
            container.style.flexDirection = 'column';
            container.style.gap = '5px';

            // Bouton pour Y2Mate
            const y2mateButton = document.createElement('button');
            y2mateButton.innerText = 'Télécharger via Y2Mate (FR)';
            y2mateButton.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
            y2mateButton.style.color = 'white';
            y2mateButton.style.border = 'none';
            y2mateButton.style.padding = '8px 12px';
            y2mateButton.style.fontSize = '12px';
            y2mateButton.style.cursor = 'pointer';
            y2mateButton.style.borderRadius = '5px';
            y2mateButton.style.opacity = '0.8';
            y2mateButton.onmouseenter = () => { y2mateButton.style.opacity = '1'; };
            y2mateButton.onmouseleave = () => { y2mateButton.style.opacity = '0.8'; };
            y2mateButton.onclick = () => openY2Mate(video);
            container.appendChild(y2mateButton);

            // Bouton pour SaveTheVideo (Twitter)
            const saveTheVideoButton = document.createElement('button');
            saveTheVideoButton.innerText = 'Télécharger via SaveTheVideo (Twitter)';
            saveTheVideoButton.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
            saveTheVideoButton.style.color = 'white';
            saveTheVideoButton.style.border = 'none';
            saveTheVideoButton.style.padding = '8px 12px';
            saveTheVideoButton.style.fontSize = '12px';
            saveTheVideoButton.style.cursor = 'pointer';
            saveTheVideoButton.style.borderRadius = '5px';
            saveTheVideoButton.style.opacity = '0.8';
            saveTheVideoButton.onmouseenter = () => { saveTheVideoButton.style.opacity = '1'; };
            saveTheVideoButton.onmouseleave = () => { saveTheVideoButton.style.opacity = '0.8'; };
            saveTheVideoButton.onclick = () => openSaveTheVideo(video);
            container.appendChild(saveTheVideoButton);

            video.parentNode.style.position = 'relative';
            video.parentNode.appendChild(container);
        });
    }

    function openY2Mate(video) {
        let videoUrl = video.querySelector('source')?.src || video.src;
        if (!videoUrl) {
            alert('Impossible de détecter la vidéo');
            return;
        }

        if (window.location.hostname.includes('youtube.com')) {
            const videoId = new URLSearchParams(window.location.search).get('v');
            if (videoId) {
                // Version française de Y2Mate pour YouTube
                window.open(`https://www.y2mate.com/fr/youtube/${videoId}`, '_blank');
                return;
            }
        }

        alert("Ce site ne permet pas la récupération directe via Y2Mate.");
    }

    function openSaveTheVideo(video) {
        let videoUrl = video.querySelector('source')?.src || video.src;
        if (!videoUrl) {
            alert('Impossible de détecter la vidéo');
            return;
        }

        // Vérification si l'URL provient de X (anciennement Twitter)
        if (window.location.hostname.includes('x.com')) {
            // Récupère l'URL du tweet à partir de la page
            const tweetUrl = window.location.href;  // L'URL du tweet
            window.open(`https://www.savethevideo.com/?url=${encodeURIComponent(tweetUrl)}`, '_blank');
            return;
        }

        alert("Ce site ne permet pas la récupération directe via SaveTheVideo.");
    }

    function observeDOMChanges() {
        const observer = new MutationObserver(addDownloadButtons);
        observer.observe(document.body, { childList: true, subtree: true });
    }

    function toggleButtonsVisibility() {
        isButtonVisible = !isButtonVisible;
        document.querySelectorAll('div').forEach(container => {
            if (container.childNodes.length && container.childNodes[0].innerText.includes('Télécharger via')) {
                container.style.display = isButtonVisible ? 'block' : 'none';
            }
        });
    }

    document.addEventListener('keydown', (event) => {
        if (event.key === 'h') { // Appuyer sur 'h' pour masquer/afficher les boutons
            toggleButtonsVisibility();
        }
    });

    window.addEventListener('load', () => {
        addDownloadButtons();
        observeDOMChanges();
    });

})();

QingJ © 2025

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