🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Youtube Video Downloader | MP3,MP4

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

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.

ستحتاج إلى تثبيت إضافة مثل 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.08.12.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
// @license MIT
// ==/UserScript==

/* jshint esversion:6 */

(function () {
    'use strict';

    const downloadButton = document.createElement("div");

    downloadButton.innerHTML = "<b>&#x2913;</b>";
    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 = "6px 14px";
    downloadButton.style.marginTop = "10px";
    downloadButton.style.userSelect = "none";
    downloadButton.style.fontSize = "2rem";
    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.style.zIndex = 999;

    const createButton = (target, callback) => {
        const btn = downloadButton.cloneNode(true);
        const content = document.createElement("div");
        const tooltip = document.createElement("tp-yt-paper-tooltip");

        tooltip.setAttribute("offset", 4);
        tooltip.textContent = "Download Video";

        content.style.position = "absolute";
        content.style.width = "200px";
        content.style.right = 0;

        content.appendChild(btn);
        content.appendChild(tooltip);
        target.appendChild(content);

        btn.onclick = () => callback();
    };

    const waitForElement = (selector, callback) => {
        const element = document.querySelector(selector);

        if (element) return callback(element);

        return window.requestAnimationFrame(() => {
            waitForElement(selector, callback);
        });
    };

    const dl = (url) => {
        const videoId = new URL(url || window.location).searchParams.get("v");
        const api = `https://saveanyvideo.com/#url=https://youtu.be/${videoId}`;

        const win = window.open(api, "_blank");
        const video = document.querySelector("video");

        video.pause();

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

    const selector = [
        "ytd-player#ytd-player:not([data-has-download-button])",
        "ytd-rich-grid-media a#thumbnail:not([data-has-download-button])",
        "ytd-rich-grid-slim-media a#thumbnail:not([data-has-download-button])",
        // "ytd-compact-video-renderer a#thumbnail:not([data-has-download-button])",
    ];

    const addButtons = () => {
        document.querySelectorAll(selector).forEach((element) => {
            const localName = element.closest("ytd-rich-grid-slim-media")?.localName;
            const target = element.parentElement;
            let url = element.href;

            if (localName === "ytd-rich-grid-slim-media") {
                url += `?v=${url.split("/").pop()}`;
            }

            element.dataset.hasDownloadButton = true;

            createButton(target, () => dl(url));
        });
    };

    window.onload = () => {
        addButtons();

        const elementNext = document.querySelector("ytd-watch-next-secondary-results-renderer");
        const elementBrowse = document.querySelector("ytd-browse");
        const element = elementBrowse ? elementBrowse : elementNext;

        if (element) {
            let mutationTimeout = null;

            element.addEventListener("DOMNodeInserted", (e) => {
                if (e.target.localName !== "ytd-rich-grid-row") return;

                clearTimeout(mutationTimeout);

                mutationTimeout = setTimeout(addButtons, 750);
            });
        }
    };
})();