Download video/audio from YouTube quickly via SaveFrom

Adds buttons in userscript manager on YouTube videos to go to SaveFrom and get video or audio, and automatically selects and downloads the highest quality video/audio on SaveFrom links

当前为 2024-03-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Download video/audio from YouTube quickly via SaveFrom
  3. // @namespace https://github.com/AbdurazaaqMohammed/userscripts
  4. // @version 1.0.1.1
  5. // @description Adds buttons in userscript manager on YouTube videos to go to SaveFrom and get video or audio, and automatically selects and downloads the highest quality video/audio on SaveFrom links
  6. // @match https://en.savefrom.net/*
  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. (function() {
  18. 'use strict';
  19. const url = window.location.href;
  20. const saveF = 'https://en.savefrom.net/';
  21. function overrideTimeout() {
  22. const originalSetTimeout = window.setTimeout;
  23. window.setTimeout = function(callback, delay) {
  24. return originalSetTimeout(callback, 1);
  25. };
  26. }
  27. function getHighestQuality() {
  28. // Get all the video download links on the page
  29. const links = document.querySelectorAll('.main > div.link-group > .ga_track_events.subname.link-download.link');
  30. const format = GM_getValue('format') ? 'MP4' : 'Audio';
  31. // Iterate through the video download links
  32. for (let i = 0; i < links.length; i++) {
  33. const link = links[i];
  34. if(link.innerText.startsWith(format)) { //actually the links are already sorted in order of quality
  35. link.click();
  36. break;
  37. }
  38. }
  39. set = setInterval(function() { //close the tab after a few seconds. if your browser opens the download in an inbuilt video/audio player this should not close it.
  40. window.close();
  41. clearInterval(set);
  42. }, 2000);
  43. }
  44. function dlV() {
  45. GM_setValue('format', true);
  46. window.open(saveF + url, '_blank').focus();
  47. }
  48. function dlA() {
  49. GM_setValue('format', false);
  50. window.open(saveF + url, '_blank').focus();
  51. }
  52. if(url.startsWith(saveF)) {
  53. overrideTimeout();
  54. const intervalId = setInterval(function() {
  55. if (document.querySelector('.links')) {
  56. clearInterval(intervalId);
  57. getHighestQuality();
  58. }
  59. }, 200);
  60. } else {
  61. GM_registerMenuCommand('Download Video', dlV);
  62. GM_registerMenuCommand('Download Audio', dlA);
  63. }
  64. })();