YouTube™ Multi Downloader v0.3

This script adds a download button

目前为 2024-02-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube™ Multi Downloader v0.3
  3. // @description This script adds a download button
  4. // @version 0.3
  5. // @date 2024-02-5
  6. // @icon https://i.imgur.com/InuDDVK.png
  7. // @compatible chrome
  8. // @compatible firefox
  9. // @compatible opera
  10. // @compatible safari
  11. // @compatible edge
  12. // @license CC-BY-NC-ND-4.0
  13. // @match *://*.youtube.com/*
  14. // @require https://code.jquery.com/jquery-3.6.0.min.js
  15. // @run-at document-end
  16. // @namespace https://greasyfork.org/users/1257725
  17. // ==/UserScript==
  18.  
  19. // Load the Google API script
  20. var script = document.createElement('script');
  21. script.src = 'https://apis.google.com/js/platform.js';
  22. document.head.appendChild(script);
  23.  
  24. if (typeof _youtube === 'undefined') {
  25. var _youtube = {
  26. currentLink: '//yt1s.ltd',
  27. currentMedia: null,
  28.  
  29. init: function () {
  30. _youtube.pageLoad();
  31. },
  32.  
  33. addClick: function () {
  34. if (location.href.includes('youtube.com') && /v=[a-zA-Z0-9-_]{11}/.test(location.href)) {
  35. var tubeID = RegExp.lastMatch.substr(2);
  36. var newInterface = $('#meta-contents');
  37.  
  38. if (newInterface.length) {
  39. // Add retro button styles
  40. const retroStyles = `
  41. /* Your existing styles here */
  42. .custom-button.round-button {
  43. border-radius: 50px;
  44. }
  45.  
  46. /* Additional styles for button */
  47. .custom-button {
  48. display: inline-block;
  49. text-decoration: none;
  50. padding: 0.5rem 1rem;
  51. border: none;
  52. background-color: #ff0000; /* YouTube red background color */
  53. color: #fff; /* White text color */
  54. font-family: "Roboto", "Arial", sans-serif;
  55. text-align: center;
  56. font-size: 14px;
  57. line-height: 1.5;
  58. cursor: pointer;
  59. transition: background-color 0.3s ease-in-out;
  60. }
  61.  
  62. .custom-button:hover {
  63. background-color: #ff5555; /* Darker red on hover */
  64. }
  65. `;
  66.  
  67. // Append retro styles to the head of the document
  68. $('head').append(`<style>${retroStyles}</style>`);
  69.  
  70. // Load Font Awesome CSS (not needed anymore, as there is no icon)
  71. // var fontAwesomeCSS = `
  72. // @import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css');
  73. // `;
  74. // $('head').append(`<style>${fontAwesomeCSS}</style>`);
  75.  
  76. // Create and append the download button
  77. var addButton = $('<div class="style-scope ytd-watch-metadata" id="_youtube" style=""><a class="custom-button round-button" target="_blank" href="' + _youtube.currentLink + '/https://youtube.com/watch?v=' + tubeID + '">Download</a></div>');
  78. var subsBtn = $('#subscribe-button');
  79. subsBtn.before(addButton[0]);
  80.  
  81. // Create and append the YouTube subscribe button
  82. var subscribeButton = $('<div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-layout="default" data-count="default"></div>');
  83. subsBtn.before(subscribeButton[0]);
  84. }
  85. }
  86. },
  87.  
  88. pageLoad: function () {
  89. if (document.body && document.domain === 'www.youtube.com') {
  90. setInterval(_youtube.inspectPg, 1000);
  91. _youtube.inspectPg();
  92. }
  93. },
  94.  
  95. inspectPg: function () {
  96. if (_youtube.currentMedia !== location.href && typeof ytplayer !== 'undefined' && ytplayer) {
  97. _youtube.currentMedia = location.href;
  98. if ($('#_youtube').length) {
  99. $('#_youtube').remove();
  100. }
  101. }
  102. if ($('#meta-contents')[0] && !$('#_youtube')[0] && typeof ytplayer !== 'undefined' && ytplayer) {
  103. _youtube.addClick();
  104. }
  105. },
  106. };
  107. }
  108.  
  109. // Initialize the script
  110. _youtube.init();