Simple YouTube MP3/VIDEO Buttons

Add two download buttons to YouTube videos that allow you to download MP3 or Video without leaving the page with the option to choose the quality.

当前为 2018-08-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Simple YouTube MP3/VIDEO Buttons
  3. // @namespace https://youtubemp3api.com/
  4. // @version 0.4
  5. // @description Add two download buttons to YouTube videos that allow you to download MP3 or Video without leaving the page with the option to choose the quality.
  6. // @author Arari, dLehr, Rene (edited)
  7. // @include http*://*.youtube.com/*
  8. // @include http*://youtube.com/*
  9. // @include http*://*.youtu.be/*
  10. // @include http*://youtu.be/*
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. var lastId = ""
  15. function getYTId(url){
  16. var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  17. var match = url.match(regExp);
  18. return (match&&match[7].length==11)? match[7] : false;
  19. }
  20.  
  21. function audioMp3(){
  22.  
  23. /* Create button */
  24. var buttonDiv = document.createElement("div");
  25. buttonDiv.style.width = "100%";
  26. buttonDiv.id = "parentButton";
  27. var addButton = document.createElement("button");
  28. addButton.appendChild(document.createTextNode("Download MP3"));
  29. if(typeof(document.getElementById("iframeDownloadButton")) != 'undefined' && document.getElementById("iframeDownloadButton") !== null)
  30. {
  31.  
  32. document.getElementById("iframeDownloadButton").remove();
  33.  
  34. }
  35.  
  36. addButton.style.width = "100%";
  37. addButton.style.backgroundColor = "#181717";
  38. addButton.style.color = "white";
  39. addButton.style.textAlign = "center";
  40. addButton.style.padding = "10px";
  41. addButton.style.marginTop = "5px";
  42. addButton.style.fontSize = "14px";
  43. addButton.style.border = "0";
  44. addButton.style.cursor = "pointer";
  45. addButton.style.borderRadius = "2px";
  46. addButton.style.fontFamily = "Roboto, Arial, sans-serif";
  47.  
  48. addButton.onclick = function () {
  49. if(document.getElementById("iframeDownloadButton") !== null)
  50. {
  51.  
  52. document.getElementById("iframeDownloadButton").remove();
  53.  
  54. }
  55. /* Add large button on click */
  56. var ytId = getYTId(location.href);
  57. if(!ytId)return;
  58. var addIframe = document.createElement("iframe");
  59. addIframe.src = '//www.recordmp3.co/#/watch?v='+ytId + '&layout=button';
  60. addIframe.style.width = "300px";
  61. addIframe.style.height = "40px";
  62. addIframe.style.marginTop = "0px";
  63. addIframe.border = "0px";
  64. addIframe.id = "iframeDownloadButton";
  65. var targetElement = document.querySelectorAll("[id='meta']");
  66.  
  67. for(var i = 0; i < targetElement.length; i++){
  68.  
  69. if(targetElement[i].className.indexOf("ytd-watch") > -1)
  70. {
  71.  
  72. targetElement[i].insertBefore(addIframe, targetElement[i].childNodes[0]);
  73. }
  74. }
  75.  
  76. };
  77.  
  78. buttonDiv.appendChild(addButton);
  79.  
  80. /* Find and add to target */
  81. var targetElement = document.querySelectorAll("[id='subscribe-button']");
  82.  
  83. for(var i = 0; i < targetElement.length; i++){
  84.  
  85. if(targetElement[i].className.indexOf("ytd-video-secondary-info-renderer") > -1){
  86.  
  87. targetElement[i].appendChild(buttonDiv);
  88.  
  89. }
  90.  
  91. }
  92.  
  93. }
  94.  
  95.  
  96. function videoMp4(){
  97.  
  98. /* Create button */
  99. var buttonDiv = document.createElement("div");
  100. buttonDiv.style.width = "100%";
  101. buttonDiv.id = "parentButton";
  102. var addButton = document.createElement("button");
  103. addButton.appendChild(document.createTextNode("Download VIDEO"));
  104. if(typeof(document.getElementById("iframeDownloadButton")) != 'undefined' && document.getElementById("iframeDownloadButton") !== null){
  105.  
  106. document.getElementById("iframeDownloadButton").remove();
  107.  
  108. }
  109.  
  110. addButton.style.width = "100%";
  111. addButton.style.backgroundColor = "#181717";
  112. addButton.style.color = "white";
  113. addButton.style.textAlign = "center";
  114. addButton.style.padding = "10px";
  115. addButton.style.marginTop = "5px";
  116. addButton.style.fontSize = "14px";
  117. addButton.style.border = "0";
  118. addButton.style.cursor = "pointer";
  119. addButton.style.borderRadius = "2px";
  120. addButton.style.fontFamily = "Roboto, Arial, sans-serif";
  121.  
  122. addButton.onclick = function () {
  123.  
  124. if(document.getElementById("iframeDownloadButton") !== null)
  125. {
  126.  
  127. document.getElementById("iframeDownloadButton").remove();
  128. }
  129. /* Add large button on click */
  130. var ytId = getYTId(location.href);
  131. if(!ytId)return;
  132. var addIframe = document.createElement("iframe");
  133. addIframe.src = '//www.recordmp3.co/#/watch?v=' + ytId + '&layout=button&format=video';
  134. addIframe.style.width = "300px";
  135. addIframe.style.height = "40px";
  136. addIframe.style.marginTop = "0px";
  137. addIframe.border = "0px";
  138. addIframe.id = "iframeDownloadButton";
  139. var targetElement = document.querySelectorAll("[id='meta']");
  140.  
  141. for(var i = 0; i < targetElement.length; i++){
  142.  
  143. if(targetElement[i].className.indexOf("ytd-watch") > -1){
  144.  
  145. targetElement[i].insertBefore(addIframe, targetElement[i].childNodes[0]);
  146.  
  147. }
  148. }
  149.  
  150. };
  151.  
  152. buttonDiv.appendChild(addButton);
  153.  
  154. /* Find and add to target */
  155. var targetElement = document.querySelectorAll("[id='subscribe-button']");
  156.  
  157. for(var i = 0; i < targetElement.length; i++){
  158.  
  159. if(targetElement[i].className.indexOf("ytd-video-secondary-info-renderer") > -1){
  160.  
  161. targetElement[i].appendChild(buttonDiv);
  162.  
  163. }
  164.  
  165. }
  166. }
  167.  
  168. if(document.getElementById("polymer-app") || document.getElementById("masthead") || window.Polymer){
  169.  
  170. setInterval(function(){
  171.  
  172. if(window.location.href.indexOf("watch?v=") < 0){
  173.  
  174. return false;
  175.  
  176. }
  177.  
  178. if(document.getElementById("count") && document.getElementById("parentButton") === null){
  179.  
  180. audioMp3(), videoMp4();
  181.  
  182. }
  183.  
  184. }, 100);
  185.  
  186. }
  187.  
  188. else{
  189.  
  190. standardInject();
  191.  
  192. }