Youtube Video Downloader | MP3,MP4

A basic youtube video downloader using y2mate, faster, a single click!

当前为 2022-04-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Youtube Video Downloader | MP3,MP4
// @name:pt-BR   Youtube Video Downloader | MP3,MP4
// @name:es      Youtube Video Downloader | MP3,MP4
// @namespace    http://tampermonkey.net/
// @version      2022.04.26.1
// @description  A basic youtube video downloader using y2mate, faster, a single click!
// @description:pt-BR Um downloader básico de vídeo do youtube usando y2mate, mais rápido, um único clique!
// @description:es ¡Un descargador básico de videos de YouTube usando y2mate, más rápido, con un solo clic!
// @author       misteregis
// @match        *://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// @run-at       document-end
// @license MIT
// ==/UserScript==

/* jshint esversion:6 */

(function () {
    'use strict';

    let downloadButton = document.createElement( "div" );
    let 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
            });
        });
    };

    downloadButton.id = "misteregis";
    downloadButton.textContent = "Download";
    downloadButton.style.backgroundColor = "var(--yt-spec-brand-button-background)";
    downloadButton.style.borderRadius = "2px";
    downloadButton.style.position = "absolute";
    downloadButton.style.right = 0;
    downloadButton.style.color = "var(--yt-spec-static-brand-white)";
    downloadButton.style.padding = "var(--yt-button-padding)";
    downloadButton.style.marginTop = "10px";
    downloadButton.style.userSelect = "none";
    downloadButton.style.fontSize = "var(--ytd-tab-system-font-size)";
    downloadButton.style.fontWeight = "var(--ytd-tab-system-font-weight)";
    downloadButton.style.letterSpacing = "var(--ytd-tab-system-letter-spacing)";
    downloadButton.style.textTransform = "var(--ytd-tab-system-text-transform)";
    downloadButton.style.cursor = "pointer";

    downloadButton.onclick = () => {
        const win = window.open( `https://www.y2mate.com/youtube/${new URL(window.location).searchParams.get("v")}`, "_blank" );
        const video = document.querySelector( "video" );

        video.pause();

        const timer = setInterval(() => {
            if (win.closed) {
                clearInterval(timer);
                video.play();
            }
        }, 400);
    }

    waitForElement( "ytd-player" ).then( el => el.appendChild( downloadButton ) );
})();