// ==UserScript== // @name YouTube Video Downloader // @namespace https://violentmonkey.github.io/ // @version 1.2 // @description Adds a download button to YouTube videos. // @author CaioX // @match https://www.youtube.com/* // @grant none // ==/UserScript== (function() { 'use strict'; // Function to create and insert the download button function addDownloadButton() { // Check if the button already exists if (document.getElementById('downloadButton')) return; // Create the button var button = document.createElement('button'); button.id = 'downloadButton'; button.innerText = 'Download'; button.style.padding = '10px'; button.style.backgroundColor = '#ff0000'; button.style.color = '#ffffff'; button.style.border = 'none'; button.style.borderRadius = '2px'; button.style.cursor = 'pointer'; button.style.marginLeft = '8px'; // Find the "Become a member" button or toolbar area var memberButton = document.querySelector('ytd-button-renderer.ytd-menu-renderer'); var toolbar = document.querySelector('#top-level-buttons-computed'); if (memberButton) { memberButton.parentNode.replaceChild(button, memberButton); } else if (toolbar) { toolbar.appendChild(button); } else { console.log('Toolbar or member button not found.'); return; } // Add click event to the button button.addEventListener('click', function() { var videoUrl = window.location.href; var videoId = new URLSearchParams(new URL(videoUrl).search).get('v'); if (videoId) { var downloadUrl = `https://www.y2mate.com/youtube/${videoId}`; window.open(downloadUrl, '_blank'); } else { alert('Video ID not found.'); } }); } // Function to observe changes in the page content function observePageChanges() { var targetNode = document.body; var observerConfig = { childList: true, subtree: true }; var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.addedNodes.length) { setTimeout(addDownloadButton, 1000); // Add a delay to ensure YouTube's dynamic content is fully loaded } }); }); observer.observe(targetNode, observerConfig); } // Initial call to add the download button setTimeout(addDownloadButton, 2000); // Add an initial delay to ensure YouTube is fully loaded observePageChanges(); })();