Simple Youtube Downloader

Download any video and music (audio) from Youtube

  1. // ==UserScript==
  2. // @name Simple Youtube Downloader
  3. // @version 1.1
  4. // @date 2019-09-11
  5. // @description Download any video and music (audio) from Youtube
  6. // @author han2ee
  7. // @match *://*.youtube.com/*
  8. // @namespace https://greasyfork.org/users/147254
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. if (window.location.href.indexOf("m.youtube") > 0) { // m.youbube
  15. setInterval(function() {
  16. if (window.location.href.indexOf("watch?v=") < 0) {
  17. return false;
  18. }
  19. if (document.getElementsByClassName('slim-video-metadata-title-and-badges').length > 0 && document.getElementById("videoid") === null) {
  20. Addytpolymer2();
  21. }
  22. }, 100);
  23. } else if (document.getElementById("polymer-app") || document.getElementById("masthead") || window.Polymer) {
  24. setInterval(function() {
  25. if (window.location.href.indexOf("watch?v=") < 0) {
  26. return false;
  27. }
  28. if (document.getElementById("count") && document.getElementById("videoid") === null) {
  29. Addytpolymer();
  30. }
  31. }, 100);
  32. } else {
  33. setInterval(function() {
  34. if (window.location.href.indexOf("watch?v=") < 0) {
  35. return false;
  36. }
  37. if (document.getElementById("watch7-subscription-container") && document.getElementById("videoid") === null) {
  38. AddhtmlDV();
  39. }
  40. }, 100);
  41. }
  42.  
  43. function AddhtmlDV() {
  44. if (document.getElementById("watch7-subscription-container")) {
  45. var wrap = document.getElementById('watch7-subscription-container');
  46. var button = "<div id='videoid' style='display: inline-block; margin-left: 10px; vertical-align: middle;'>";
  47. button += "<a href=\"http://144.202.106.6:988/download?url=" + window.location.href + "\" title=\"Download this video\" target=\"_blank\"" +
  48. "style=\"display: inline-block; font-size: inherit; height: 22px; border: 1px solid rgb(0, 183, 90); border-radius: 3px; padding-left: 28px; cursor: pointer; vertical-align: middle; position: relative; line-height: 22px; text-decoration: none; z-index: 1; color: rgb(255, 255, 255);\">";
  49. button += "<i style=\"position: absolute; display: inline-block; left: 6px; top: 3px; background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIiB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiB2aWV3Qm94PSIwIDAgMTYgMTYiIGlkPSJzdmcyIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBkPSJNIDQsMCA0LDggMCw4IDgsMTYgMTYsOCAxMiw4IDEyLDAgNCwwIHoiIGZpbGw9IiNmZmZmZmYiIC8+PC9zdmc+); background-size: 12px; background-repeat: no-repeat; background-position: center center; width: 16px; height: 16px;\"></i>";
  50. button += "<span style=\"padding-right: 12px;\">Download</span></a></div>";
  51. var style = "<style>#videoid button::-moz-focus-inner{padding:0;margin:0}#videoid a{background-color:#15388c}#videoid a:hover{background-color:#E91E63}#videoid a:active{background-color:rgb(0, 151, 74)}</style>";
  52. var tmp = wrap.innerHTML;
  53. wrap.innerHTML = tmp + button + style;
  54. }
  55. }
  56.  
  57. function Addytpolymer() {
  58. var buttonDiv = document.createElement("span");
  59. buttonDiv.style.width = "100%";
  60. buttonDiv.id = "videoid";
  61. var addButton = document.createElement("a");
  62. addButton.appendChild(document.createTextNode("Download Video"));
  63. addButton.style.width = "100%";
  64. addButton.style.backgroundColor = "#15388c";
  65. addButton.style.color = "white";
  66. addButton.style.textAlign = "center";
  67. addButton.style.padding = "5px 10px";
  68. addButton.style.margin = "0px 10px";
  69. addButton.style.fontSize = "14px";
  70. addButton.style.border = "0";
  71. addButton.style.cursor = "pointer";
  72. addButton.style.borderRadius = "2px";
  73. addButton.style.fontFamily = "Roboto, Arial, sans-serif";
  74. addButton.style.textDecoration = "none";
  75. addButton.href = "http://144.202.106.6:988/download?url=" + window.location.href;
  76. addButton.target = "_blank";
  77. buttonDiv.appendChild(addButton);
  78. var targetElement = document.querySelectorAll("[id='count']");
  79. for (var i = 0; i < targetElement.length; i++) {
  80. if (targetElement[i].className.indexOf("ytd-video-primary-info-renderer") > -1) {
  81. targetElement[i].appendChild(buttonDiv);
  82. }
  83. }
  84. }
  85.  
  86. function Addytpolymer2() {
  87. var buttonDiv = document.createElement("span");
  88. buttonDiv.style.width = "100%";
  89. buttonDiv.id = "videoid";
  90. var addButton = document.createElement("a");
  91. addButton.appendChild(document.createTextNode("Download Video"));
  92. addButton.style.width = "100%";
  93. addButton.style.backgroundColor = "#15388c";
  94. addButton.style.color = "white";
  95. addButton.style.textAlign = "center";
  96. addButton.style.padding = "5px 10px";
  97. addButton.style.margin = "0px 10px";
  98. addButton.style.fontSize = "14px";
  99. addButton.style.border = "0";
  100. addButton.style.cursor = "pointer";
  101. addButton.style.borderRadius = "2px";
  102. addButton.style.fontFamily = "Roboto, Arial, sans-serif";
  103. addButton.style.textDecoration = "none";
  104. addButton.href = "http://144.202.106.6:988/download?url=" + window.location.href;
  105. addButton.target = "_blank";
  106. buttonDiv.appendChild(addButton);
  107. var targetElement = document.getElementsByClassName('slim-video-metadata-title-and-badges')[0].children[2];
  108. targetElement.appendChild(buttonDiv);
  109. }
  110. })();