Youtube Downloader

Add video download button in combo menu.

目前為 2023-12-11 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name                Youtube Downloader
// @version             1.0.2
// @description         Add video download button in combo menu.
// @author              FawayTT
// @namespace           FawayTT
// @icon                https://i.imgur.com/D57wQrY.png
// @match               https://www.youtube.com/watch*
// @grant               none
// @license             MIT
// ==/UserScript==

(function () {
  let timeout;
  let replaced = false;

  function addButton() {
    if (document.location.href.includes('playlist') || document.getElementsByTagName('custom-dwn-button').length !== 0) return;
      const menu = document.getElementsByTagName('ytd-menu-popup-renderer')[0];
      const downButton = document.createElement('custom-dwn-button');
      const icon = document.createElement('div');
      const text = document.createElement('div');
      menu.style.minHeight = '100px';
      downButton.style.cssText = `
          cursor: pointer;
          margin-top: 8px;
          font-size: 1.4rem;
          line-height: 2rem;
          font-weight: 400;
          position: relative;
          color: var(--yt-spec-text-primary);
          font-family: "Roboto","Arial",sans-serif;
          white-space: nowrap;
          display: flex;
          padding: 10px 0 10px 21px;
          gap: 21px;
          align-items: center;`;
      icon.innerText = '⇩';
      text.innerText = 'Download';
      icon.style.cssText = `
            font-size: 2.1rem;`
      downButton.appendChild(icon);
      downButton.appendChild(text);
      downButton.addEventListener('click', onClick);
      downButton.addEventListener('mouseenter', ()=>{
        downButton.style.backgroundColor = 'rgba(255,255,255,0.1)';
      });
      downButton.addEventListener('mouseleave', ()=>{
        downButton.style.backgroundColor = '';
      });
      menu.insertBefore(downButton, menu.firstChild);
  }

  function watchMenu() {
      const menu = document.getElementById('button-shape');
      menu.addEventListener('click', addButton);
      replaced = true;
      clearTimeout(timeout);
  }

  function onClick() {
      window.open(document.location.href.replace('youtube', 'youtubepp'));
  }

  if (document.hidden) {
    window.addEventListener("visibilitychange", ()=>{
      if (document.hidden) return;
      for (let i = 0; i < 10; i++) {
         if (replaced) break;
         timeout = setTimeout(watchMenu, 500 * i);
      }
    })
  } else {
      for (let i = 0; i < 10; i++) {
         if (replaced) break;
         timeout = setTimeout(watchMenu, 500 * i);
      }
  }
})();