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)

当前为 2024-06-28 提交的版本,查看 最新版本

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