您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds a MP3 Download button with progress bar on YouTube using RapidAPI
// ==UserScript== // @name YouTube MP3 Download Button Ready // @namespace http://ninjasunite.com // @version 5.0 // @description Adds a MP3 Download button with progress bar on YouTube using RapidAPI // @match https://www.youtube.com/* // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js // @grant GM_xmlhttpRequest // @connect youtube-to-mp3-download.p.rapidapi.com // ==/UserScript== (function() { 'use strict'; // --- ВАЖНО --- // Замените 'YOUR_RAPIDAPI_KEY' на ваш собственный ключ RapidAPI const API_KEY = 'YOUR_RAPIDAPI_KEY'; const API_HOST = 'youtube-to-mp3-download.p.rapidapi.com'; function addDownloadButton() { const subButton = $('ytd-subscribe-button-renderer'); if (subButton.length && $('#youtube2mp3').length === 0) { const videoUrl = window.location.href; // Контейнер кнопки и прогресс-бар const btnContainer = $('<div id="youtube2mp3-container" style="display:inline-block; margin-left:8px; position:relative;"></div>'); const btn = $('<a id="youtube2mp3" class="yt-simple-endpoint style-scope ytd-button-renderer" style="padding:5px 12px; background-color:#ff0000; color:#fff; font-size:12px; border-radius:2px; cursor:pointer; display:inline-block;">MP3 Download</a>'); const progressBar = $('<div id="youtube2mp3-progress" style="position:absolute; bottom:0; left:0; height:3px; background-color:#00ff00; width:0%; border-radius:2px;"></div>'); btnContainer.append(btn).append(progressBar); btnContainer.insertAfter(subButton); btn.click(function(e) { e.preventDefault(); btn.text('Converting...'); btn.css('background-color','#ffa500'); progressBar.css('width','0%'); GM_xmlhttpRequest({ method: "GET", url: `https://${API_HOST}/convert?url=${encodeURIComponent(videoUrl)}&format=mp3`, headers: { "X-RapidAPI-Key": API_KEY, "X-RapidAPI-Host": API_HOST }, onprogress: function(e) { if (e.lengthComputable) { const percent = Math.round((e.loaded / e.total) * 100); progressBar.css('width', percent + '%'); } else { progressBar.css('width', '50%'); } }, onload: function(response) { try { const data = JSON.parse(response.responseText); if (data && data.link) { window.open(data.link, '_blank'); btn.text('MP3 Download'); btn.css('background-color','#ff0000'); progressBar.css('width','100%'); setTimeout(()=>progressBar.css('width','0%'), 2000); } else { btn.text('Error'); btn.css('background-color','#ff0000'); alert("Ошибка: не удалось получить ссылку на MP3."); } } catch(err) { btn.text('Error'); btn.css('background-color','#ff0000'); alert("Ошибка при обработке ответа API."); console.error(err); } }, onerror: function() { btn.text('Error'); btn.css('background-color','#ff0000'); alert("Ошибка запроса к API."); } }); }); } } // Отслеживаем динамические изменения на YouTube (SPA) const observer = new MutationObserver(addDownloadButton); observer.observe(document.body, { childList: true, subtree: true }); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址