YouTube Simple Downloader

Download videos and audio from YouTube using simple buttons in the extension menu

  1. // ==UserScript==
  2. // @name YouTube Simple Downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Download videos and audio from YouTube using simple buttons in the extension menu
  6. // @author Magneto1
  7. // @license MIT
  8. // @match https://*.youtube.com/*
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_openInTab
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Funzione per estrarre l'ID del video da YouTube
  17. function extractYT(url) {
  18. const regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  19. const match = String(url).match(regExp);
  20. return (match && match[7].length === 11) ? match[7] : false;
  21. }
  22.  
  23. // Funzione per il download del video in formato MP4
  24. function downloadVideo() {
  25. const videoId = extractYT(window.location.href);
  26. if (videoId) {
  27. const downloadUrl = `https://tubemp3.to/en/download/${videoId}/mp4`; // Modifica l'URL in base al servizio di download
  28. GM_openInTab(downloadUrl, { active: true });
  29. } else {
  30. alert("Nessun video trovato.");
  31. }
  32. }
  33.  
  34. // Funzione per il download dell'audio in formato MP3
  35. function downloadAudio() {
  36. const videoId = extractYT(window.location.href);
  37. if (videoId) {
  38. const downloadUrl = `https://tubemp3.to/en/download/${videoId}/mp3`; // Modifica l'URL in base al servizio di download
  39. GM_openInTab(downloadUrl, { active: true });
  40. } else {
  41. alert("Nessun video trovato.");
  42. }
  43. }
  44.  
  45. // Aggiungi i comandi al menu dell'estensione
  46. GM_registerMenuCommand("Download YouTube Video (MP4)", downloadVideo);
  47. GM_registerMenuCommand("Download YouTube Audio (MP3)", downloadAudio);
  48. })();