Youtube download button - y2mate

This Script Adds a Download Button on the left side of the subscribe button, you can easily download Audio/Video

// ==UserScript==
// @name            Youtube download button - y2mate
// @namespace       http://tampermonkey.net/
// @version         2.1
// @author          God Mario
// @match           *://*.youtube.com/*
// @run-at          document-start
// @icon            https://cdn.icon-icons.com/icons2/822/PNG/512/download_icon-icons.com_66472.png
// @grant           GM_addStyle
// @connect         www-y2mate.com/es34/
// @license         MIT
// @description     This Script Adds a Download Button on the left side of the subscribe button, you can easily download Audio/Video
// ==/UserScript==

(function() {
    'use strict';

    const SELECTORS = {
        subscribeButton: '#subscribe-button button',
        downloadButton: '.y2mate-download-btn'
    };

    const STRINGS = {
        downloadText: 'Download'
    };

    const STYLES = `
        .y2mate-download-btn {
            background-color: var(--yt-spec-additive-background);
            color: var(--yt-spec-text-primary);
            margin: 0px 4px;
            border-radius: 18px;
            width: 120px;
            height: 36px;
            line-height: 37px;
            text-align: center;
            font-style: normal;
            font-size: 14px;
            font-family: Roboto, Noto, sans-serif;
            font-weight: 500;
            text-decoration: none;
            display: flex;
            align-items: center;
            justify-content: center;
            text-decoration: none;
            border: none;
            cursor: pointer;
        }
        .y2mate-download-btn:hover {
            background-color: var(--yt-spec-mono-tonal-hover);
            color: var(--yt-spec-text-primary);
        }
        .y2mate-buttons-wrapper {
            display: flex;
            align-items: center;
            gap: 8px;
        }
    `;

    GM_addStyle(STYLES);

    function createDownloadButton() {
        if (document.querySelector(SELECTORS.downloadButton)) {
            return null;
        }

        const downloadButton = document.createElement('button');
        downloadButton.className = 'y2mate-download-btn';
        downloadButton.textContent = `⬇ ${STRINGS.downloadText}`;

        downloadButton.addEventListener('click', function() {
            const videoUrl = window.location.href;
            const downloadDomains = ['youtubepp.com/'];
            const newUrl = videoUrl.replace('youtube.com/', downloadDomains);
            window.open(newUrl, '_blank');
        });

        return downloadButton;
    }

    function addDownloadButton() {
        const subscribeButton = document.querySelector(SELECTORS.subscribeButton);
        if (!subscribeButton) {
            return;
        }

        const downloadButton = createDownloadButton();
        if (!downloadButton) {
            return;
        }

        const container = subscribeButton.closest('#subscribe-button');
        if (container) {
            const wrapper = document.createElement('div');
            wrapper.className = 'y2mate-buttons-wrapper';

            container.parentNode.insertBefore(wrapper, container);
            wrapper.appendChild(container);
            wrapper.appendChild(downloadButton);
        }
    }

    function init() {
        if (window.location.pathname.includes('/watch')) {
            addDownloadButton();
        }
    }

    const observer = new MutationObserver(init);

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

    window.addEventListener('yt-navigate-finish', init);

    init();

})();