YouTube Downloader (reload page!)

Adds download button for mobile and desktop site YouTube

  1. // ==UserScript==
  2. // @name YouTube Downloader (reload page!)
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0
  5. // @description Adds download button for mobile and desktop site YouTube
  6. // @author Agreasyforkuser
  7. // @match https://*.youtube.com/*
  8. // @exclude https://*.youtube.com/tv*
  9. // @icon https://www.google.com/s2/favicons?domain=youtube.com
  10. // @grant GM_addStyle
  11. // ==/UserScript==
  12.  
  13. var currentURL = window.location.href;
  14.  
  15. //////////////////////// Download Button ///////////////////////////////////////
  16.  
  17. 'use strict';
  18. // Function to handle the redirect
  19. function handleRedirect() {
  20. // Get the current YouTube video URL
  21. var currentUrl = window.location.href;
  22. // Extract the video ID from the URL
  23. var videoIdMatch = currentUrl.match(/\/watch\?v=([^&]+)/);
  24. var videoId = videoIdMatch ? videoIdMatch[1] : null;
  25. if (videoId) {
  26. // Redirect to the new URL with "pp" added
  27. var newUrl = 'https://www.youtubepp.com/watch?v=' + videoId;
  28. // Open the new URL in a new tab
  29. window.open(newUrl, '_blank');
  30. }
  31. }
  32. // Function to create and append the "Download" button
  33. function appendDownloadButton() {
  34. // Create the button element
  35. var downloadButton = document.createElement('button');
  36. //downloadButton.innerText = '';
  37. downloadButton.style.margin = '13px'; // Add some margin for better appearance
  38. downloadButton.style.color = 'white';
  39. downloadButton.style.opacity = '0.8';
  40. downloadButton.style.border = 'none';
  41. downloadButton.style.cursor = 'pointer'; // Set the cursor to pointer on hov
  42. downloadButton.addEventListener('click', handleRedirect);
  43. downloadButton.classList.add('downloadbutton');
  44. var existingElementMobile = document.querySelector('.slim-owner-icon-and-title');
  45. var existingElementDesktop = document.querySelector('.ytp-time-display');
  46. if (existingElementMobile) {
  47. existingElementMobile.parentNode.insertBefore(downloadButton, existingElementMobile.nextSibling);
  48. }
  49. if (existingElementDesktop) {
  50. existingElementDesktop.parentNode.insertBefore(downloadButton, existingElementDesktop.nextSibling);
  51. }
  52.  
  53. if (currentURL.startsWith("https://www.youtube.com")) {
  54.  
  55. GM_addStyle(`
  56. .downloadbutton:before {content: "Download 🡇" !important}
  57. .downloadbutton {background-color: black !important; border-radius: 6px !important}
  58. `);
  59. };
  60.  
  61. //---------------------------------------------------------------------------------------------------------------------------
  62. if (currentURL.startsWith("https://m.youtube.com")) {
  63.  
  64. GM_addStyle(`
  65. .downloadbutton:before {content: "Download ⤓" !important}
  66. .downloadbutton {color: gray !important; margin: 5px !important}
  67. `);
  68. };
  69. };
  70.  
  71. setTimeout(()=>{appendDownloadButton()},3000);