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)

  1. // ==UserScript==
  2. // @name Download video/audio from YouTube quickly via userscript menu
  3. // @namespace https://github.com/AbdurazaaqMohammed/userscripts
  4. // @version 1.1.2
  5. // @description Adds buttons in userscript manager on YouTube videos to download video (from ytbsave.com) or audio (from tube-nightly.kuylar.dev through poketube)
  6. // @match https://ytbsave.com/en/youtube-to-mp4/*
  7. // @match https://www.youtube.com/*
  8. // @exclude https://www.youtube.com/feed/*
  9. // @exclude https://www.youtube.com/channel/*
  10. // @grant GM_registerMenuCommand
  11. // @homepage https://github.com/AbdurazaaqMohammed/userscripts
  12. // @license The Unlicense
  13. // @supportURL https://github.com/AbdurazaaqMohammed/userscripts/issues
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. function overrideTimeout() {
  20. const originalSetTimeout = window.setTimeout;
  21. window.setTimeout = function(callback, delay) {
  22. return originalSetTimeout(callback, 1);
  23. };
  24. }
  25.  
  26. function dlV() {
  27. window.open('https://ytbsave.com/en/youtube-to-mp4/' + window.location.href, '_blank').focus();
  28. }
  29.  
  30. function dlA() {
  31. window.location.href = ('https://poketube.fun/api/video/download?v=' + window.location.href.split('v=')[1] + '&q=251&f=webm');
  32. }
  33.  
  34. if(window.location.href.startsWith('https://ytbsave.com/en/youtube-to-mp4/')) {
  35. overrideTimeout();
  36. const intervalId = setInterval(function() {
  37. document.querySelector('#mp4 > table > tbody > tr:nth-child(4) > td.text-center > button').click(); // highest quality video
  38. const s = document.querySelector(".text-center.form-group > .btn-success.btn");
  39. if(s) {
  40. clearInterval(intervalId);
  41. const bruh = setInterval(function() {
  42. // When the button first appear the href is the current url for some reason need to wait for it to load the download url
  43. if(!s.href.startsWith('https://ytbsave.com/')) {
  44. window.location.href = s.href;
  45. clearInterval(bruh);
  46. }
  47. }, 500);
  48. }
  49. }, 500);
  50. } else {
  51. GM_registerMenuCommand('Download Video', dlV);
  52. GM_registerMenuCommand('Download Audio', dlA);
  53. }
  54. })();