Youtube download button - yt1s.com (revised SuchtiOnTour Edit)

This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video

  1. // ==UserScript==
  2. // @name Youtube download button - yt1s.com (revised SuchtiOnTour Edit)
  3. // @name:de Youtube download button - yt1s.com (revised SuchtiOnTour Edit)
  4. // @namespace Violentmonkey Scripts
  5. // @match https://www.youtube.com/watch
  6. // @match https://*.youtube.com/*
  7. // @grant GM_addStyle
  8. // @run-at document-idle
  9. // @version 1.2.5
  10. // @author SuchtiOnTour
  11. // @license MIT
  12. // @description This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  13. // @description:pt-BR This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  14. // @description:ar This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  15. // @description:bg This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  16. // @description:cs This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  17. // @description:da This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  18. // @description:de This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  19. // @description:el This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  20. // @description:eo This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  21. // @description:es This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  22. // @description:fi This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  23. // @description:fr This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  24. // @description:fr-CA This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  25. // @description:he This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  26. // @description:hu This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  27. // @description:id This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  28. // @description:it This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  29. // @description:ja This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  30. // @description:ko This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  31. // @description:nb This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  32. // @description:nl This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  33. // @description:pl This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  34. // @description:ro This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  35. // @description:ru This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  36. // @description:sk This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  37. // @description:sr This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  38. // @description:sv This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  39. // @description:th This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  40. // @description:tr This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  41. // @description:uk This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  42. // @description:ug This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  43. // @description:vi This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  44. // @description:zh-CN This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  45. // @description:zh-TW This Script Adds a Download Button next to the subscribe button, you can easily download Audio/Video
  46. // ==/UserScript==
  47.  
  48. (function() {
  49. const API = "https://yt1s.com/en/youtube-to-mp3?q=";
  50. const BUTTON_ID = "dwnldBtn";
  51. const TARGET_BUTTON = "#owner"; // Updated target element selector
  52.  
  53. const buttonStyle = `
  54. #${BUTTON_ID} {
  55. background-color: #0F0F0F;
  56. color: #FFFFFF;
  57. border: 1px solid #3F3F3F;
  58. border-color: rgba(255,255,255,0.2);
  59. margin-left: 8px; /* Decreased margin-left to 8px for smaller gap */
  60. padding: 0 16px;
  61. border-radius: 18px; /* Updated border radius */
  62. font-size: 14px;
  63. font-family: Roboto, Noto, sans-serif;
  64. font-weight: 500;
  65. text-decoration: none;
  66. display: inline-flex;
  67. align-items: center;
  68. height: 36px;
  69. line-height: normal;
  70. }
  71. #${BUTTON_ID}:hover {
  72. background-color: #3F3F3F;
  73. color: #ffffff;
  74. border-color: #3F3F3F;
  75. }
  76. `;
  77.  
  78. GM_addStyle(buttonStyle);
  79.  
  80. function waitForElement(selector) {
  81. return new Promise(resolve => {
  82. if (document.querySelector(selector)) {
  83. console.log(`[Youtube Download Button]: Video Found, checking if button exists...`);
  84. return resolve(document.querySelector(selector));
  85. }
  86. const observer = new MutationObserver(mutations => {
  87. if (document.querySelector(selector)) {
  88. console.log(`[Youtube Download Button]: Video Found by observer, checking if button exists...`);
  89. resolve(document.querySelector(selector));
  90. observer.disconnect();
  91. }
  92. });
  93. observer.observe(document.body, { childList: true, subtree: true });
  94. });
  95. }
  96.  
  97. function addButton() {
  98. waitForElement(TARGET_BUTTON).then((btnContainer) => {
  99. if (!btnContainer) {
  100. return;
  101. }
  102.  
  103. if (document.querySelector(`#${BUTTON_ID}`)) { // Check if the button already exists
  104. console.log(`[Youtube Download Button]: Download button exists`);
  105. } else {
  106. const downloadButton = document.createElement('a');
  107. downloadButton.href = `${API + encodeURIComponent(window.location.href)}`;
  108. downloadButton.target = '_blank';
  109. downloadButton.id = BUTTON_ID;
  110. downloadButton.innerText = 'Download';
  111. btnContainer.appendChild(downloadButton);
  112. console.log(`[Youtube Download Button]: Button added successfully`);
  113. }
  114. }).catch(error => {
  115. console.error(`[Youtube Download Button]: Error adding button: ${error}`);
  116. });
  117. }
  118.  
  119. function updateButton() {
  120. waitForElement(`#${BUTTON_ID}`).then((btn) => {
  121. if (!btn) {
  122. return;
  123. }
  124. btn.href = API + encodeURIComponent(window.location.href);
  125. }).catch(error => {
  126. console.error(`[Youtube Download Button]: Error updating button: ${error}`);
  127. });
  128. }
  129.  
  130. let buttonAdded = false;
  131.  
  132. function checkAndAddButton() {
  133. if (window.location.pathname === '/watch' && !buttonAdded) {
  134. addButton();
  135. buttonAdded = true;
  136. setTimeout(updateButton, 2000); // Delay of 2 seconds for update
  137. }
  138. }
  139.  
  140. window.addEventListener("yt-navigate-finish", () => {
  141. buttonAdded = false; // Reset flag when navigation happens
  142. checkAndAddButton();
  143. });
  144.  
  145. checkAndAddButton(); // Initial check when script runs
  146. })();