Ajoute des boutons pour télécharger des vidéos via Y2Mate, SaveTheVideo et SSSTwitter
当前为
// ==UserScript==
// @name DL Videos
// @namespace https://greasyfork.org/
// @version 1.0
// @description Ajoute des boutons pour télécharger des vidéos via Y2Mate, SaveTheVideo et SSSTwitter
// @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';
const buttons = [
{ text: 'Télécharger via Y2Mate', url: 'https://www.y2mate.com/es/youtube/' },
{ text: 'Télécharger via SaveTheVideo', url: 'https://www.savethevideo.com/download?url=' },
{ text: 'Télécharger via SSSTwitter', url: 'https://ssstwitter.com/' }
];
buttons.forEach(({ text, url }) => {
const button = document.createElement('button');
button.innerText = text;
button.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
button.style.color = 'white';
button.style.border = 'none';
button.style.padding = '8px 12px';
button.style.fontSize = '12px';
button.style.cursor = 'pointer';
button.style.borderRadius = '5px';
button.style.opacity = '0.8';
button.onmouseenter = () => { button.style.opacity = '1'; };
button.onmouseleave = () => { button.style.opacity = '0.8'; };
button.onclick = () => openDownloadSite(video, url);
container.appendChild(button);
});
video.parentNode.style.position = 'relative';
video.parentNode.appendChild(container);
});
}
function openDownloadSite(video, baseUrl) {
let videoUrl = video.querySelector('source')?.src || video.src;
if (!videoUrl) {
alert('Impossible de détecter la vidéo');
return;
}
if (baseUrl.includes('y2mate')) {
const videoId = new URLSearchParams(window.location.search).get('v');
if (videoId) {
window.open(`${baseUrl}${videoId}`, '_blank');
return;
}
}
window.open(`${baseUrl}${encodeURIComponent(videoUrl)}`, '_blank');
}
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[0]?.innerText.includes('Télécharger via')) {
container.style.display = isButtonVisible ? 'flex' : 'none';
}
});
}
document.addEventListener('keydown', (event) => {
if (event.key === 'h') { // Appuyer sur 'h' pour masquer/afficher les boutons
toggleButtonsVisibility();
}
});
window.addEventListener('load', () => {
addDownloadButtons();
observeDOMChanges();
});
})();