YouTube Simple Downloader

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         YouTube Simple Downloader
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Download videos and audio from YouTube using simple buttons in the extension menu
// @author       Magneto1
// @license      MIT
// @match        https://*.youtube.com/*
// @grant        GM_registerMenuCommand
// @grant        GM_openInTab
// ==/UserScript==

(function() {
    'use strict';

    // Funzione per estrarre l'ID del video da YouTube
    function extractYT(url) {
        const regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
        const match = String(url).match(regExp);
        return (match && match[7].length === 11) ? match[7] : false;
    }

    // Funzione per il download del video in formato MP4
    function downloadVideo() {
        const videoId = extractYT(window.location.href);
        if (videoId) {
            const downloadUrl = `https://tubemp3.to/en/download/${videoId}/mp4`; // Modifica l'URL in base al servizio di download
            GM_openInTab(downloadUrl, { active: true });
        } else {
            alert("Nessun video trovato.");
        }
    }

    // Funzione per il download dell'audio in formato MP3
    function downloadAudio() {
        const videoId = extractYT(window.location.href);
        if (videoId) {
            const downloadUrl = `https://tubemp3.to/en/download/${videoId}/mp3`; // Modifica l'URL in base al servizio di download
            GM_openInTab(downloadUrl, { active: true });
        } else {
            alert("Nessun video trovato.");
        }
    }

    // Aggiungi i comandi al menu dell'estensione
    GM_registerMenuCommand("Download YouTube Video (MP4)", downloadVideo);
    GM_registerMenuCommand("Download YouTube Audio (MP3)", downloadAudio);
})();