YouTube™ Multi Downloader v9.1 🌐🚀💯 - Y2Mate.com (NO ADS & NEW LAYOUT FOR YT! 🚫🤩)

This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name YouTube™ Multi Downloader v9.1 🌐🚀💯 - Y2Mate.com (NO ADS & NEW LAYOUT FOR YT! 🚫🤩)
// @name:pt-BR YouTube™ Multi Downloader v9.1 🌐🚀💯 - Y2Mate.com (SEM ANÚNCIOS & NOVO LAYOUT PARA YT! 🚫🤩)
// @description This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:pt-BR Esse script adiciona um botão de download, uma maneira mais rápida de baixar áudio e vídeo do YouTube e com qualidade garantida. Este site é muito simples, rápido e eficaz para baixar! Melhor de todos!
// @description:ar This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:bg This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:cs This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:da This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:de This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:el This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:eo This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:es This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:fi This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:fr This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:fr-CA This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:he This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:hu This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:id This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:it This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:ja This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:ko This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:nb This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:nl This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:pl This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:ro This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:ru This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:sk This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:sr This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:sv This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:th This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:tr This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:uk This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:ug This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:vi This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:zh-CN This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @description:zh-TW This script adds a download button, a faster way to download audio and video from YouTube with guaranteed quality. This site is very simple, fast and effective to download! Best of all!
// @namespace https://greasyfork.org/users/1173123
// @homepageURL https://greasyfork.org/scripts/475299
// @supportURL https://greasyfork.org/scripts/475299/feedback
// @author RichBeforeDeath
// @version 9.1
// @date 2024-09-04
// @icon https://i.imgur.com/InuDDVK.png
// @compatible chrome
// @compatible firefox
// @compatible opera
// @compatible safari
// @compatible edge
// @license CC-BY-NC-ND-4.0
// @match https://*.youtube.com/*
// @grant GM_addStyle
// @run-at document-idle
// ==/UserScript==

(function() {
    var y2mateURL = "https://www.y2mate.com/youtube/";
    var buttonID = "dwnldBtn";
    var currentButton = "#owner";

    var buttonStyle = `
    #${buttonID} {
        background-color: #F1F1F1;
        color: #191919;
        border: 1px solid rgba(255,255,255,0.2);
        margin-left: 8px;
        padding: 0 16px;
        border-radius: 18px;
        font-size: 14px;
        font-family: Roboto, Noto, sans-serif;
        font-weight: 500;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        height: 36px;
        line-height: normal;
    }
    #${buttonID}:hover {
        background-color: #D9D9D9;
        color: #191919;
        border-color: #F1F1F1;
    }
    `;

    GM_addStyle(buttonStyle);

    function waitForElement(selector) {
        return new Promise(resolve => {
            if (document.querySelector(selector)) {
                return resolve(document.querySelector(selector));
            }

            const observer = new MutationObserver(mutations => {
                if (document.querySelector(selector)) {
                    resolve(document.querySelector(selector));
                    observer.disconnect();
                }
            });

            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
        });
    }

    function addButton() {
        waitForElement(currentButton).then((buttonContainer) => {
            if (!buttonContainer) return;

            if (!document.querySelector(`#${buttonID}`)) {
                var downloadBtn = document.createElement('a');
                downloadBtn.href = `${y2mateURL}${extractVideoID(window.location)}`;
                downloadBtn.target = '_blank';
                downloadBtn.id = buttonID;
                downloadBtn.innerText = 'Download';
                buttonContainer.appendChild(downloadBtn);
            }
        });
    }

    function updateButtonURL() {
        waitForElement(`#${buttonID}`).then((btn) => {
            if (!btn) return;
            btn.href = `${y2mateURL}${extractVideoID(window.location)}`;
        });
    }

    function extractVideoID(url) {
        var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
        var match = String(url).match(regExp);
        return (match && match[7].length == 11) ? match[7] : false;
    }

    let buttonSet = false;

    function checkButton() {
        if (window.location.pathname === '/watch' && !buttonSet) {
            addButton();
            buttonSet = true;
            setTimeout(updateButtonURL, 2000);
        }
    }

    window.addEventListener("yt-navigate-finish", () => {
        buttonSet = false;
        checkButton();
    });

    checkButton();
})();