Download video/audio from YouTube quickly via userscript menu

Adds buttons in userscript manager on YouTube videos to download video (from ytbsave.com) or audio (from tube-nightly.kuylar.dev through poketube)

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install an extension such as Stylus to install this style.

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

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

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

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        Download video/audio from YouTube quickly via userscript menu
// @namespace   https://github.com/AbdurazaaqMohammed/userscripts
// @version     1.1.2
// @description Adds buttons in userscript manager on YouTube videos to download video (from ytbsave.com) or audio (from tube-nightly.kuylar.dev through poketube)
// @match       https://ytbsave.com/en/youtube-to-mp4/*
// @match       https://www.youtube.com/*
// @exclude     https://www.youtube.com/feed/*
// @exclude     https://www.youtube.com/channel/*
// @grant       GM_registerMenuCommand
// @homepage    https://github.com/AbdurazaaqMohammed/userscripts
// @license     The Unlicense
// @supportURL  https://github.com/AbdurazaaqMohammed/userscripts/issues
// ==/UserScript==

(function() {
  'use strict';

  function overrideTimeout() {
    const originalSetTimeout = window.setTimeout;
    window.setTimeout = function(callback, delay) {
      return originalSetTimeout(callback, 1);
    };
  }

  function dlV() {
    window.open('https://ytbsave.com/en/youtube-to-mp4/' + window.location.href, '_blank').focus();
  }

  function dlA() {
    window.location.href = ('https://poketube.fun/api/video/download?v=' + window.location.href.split('v=')[1] + '&q=251&f=webm');
  }

  if(window.location.href.startsWith('https://ytbsave.com/en/youtube-to-mp4/')) {
    overrideTimeout();
    const intervalId = setInterval(function() {
      document.querySelector('#mp4 > table > tbody > tr:nth-child(4) > td.text-center > button').click(); // highest quality video
      const s = document.querySelector(".text-center.form-group > .btn-success.btn");
      if(s) {
        clearInterval(intervalId);
        const bruh = setInterval(function() {
          // When the button first appear the href is the current url for some reason need to wait for it to load the download url
          if(!s.href.startsWith('https://ytbsave.com/')) {
            window.location.href = s.href;
            clearInterval(bruh);
          }
        }, 500);
      }
    }, 500);
  } else {
    GM_registerMenuCommand('Download Video', dlV);
    GM_registerMenuCommand('Download Audio', dlA);
  }
})();