YouTube.com Video download helper

Adds a button to open a Video download website.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YouTube.com Video download helper
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Adds a button to open a Video download website.
// @author       Kvali
// @match        https://www.youtube.com/watch*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    function getRightControls(){
        return document.getElementsByClassName('ytp-right-controls')[0];
    }

    function download(){
    var id = window.location.search.split('v=')[1];
    let hrefDownload ='https://www.y2mate.com/youtube/' + id.split('&t=')[0];
      window.open(hrefDownload, '_blank');
    }

    function createButton(){
        const swb = document.createElement('button');
        swb.classList.add('ytp-button');
        swb.classList.add('downloadBTN');
        swb.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 320"><rect width="100%" height="100%" fill="none"/><polyline points="86 110 128 152 170 110" fill="#fff" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="24"/><line x1="128" y1="40" x2="128" y2="152" fill="#fff" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="24"/><path d="M216,152v56a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V152" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="24"/></svg>`;
        swb.title = 'Set current playback time to URL (u)';
        swb.onclick = download;
        return swb;
    }

    let panel = getRightControls();
    panel.insertBefore(createButton(), panel.firstChild);
})();