// ==UserScript== // @name B站音频一键下载 // @namespace http://tampermonkey.net/ // @version 1.3 // @description (从B站下载歌曲)一键下载B站视频的音频,自动命名标题 // @author 豆包助手 // @match https://www.bilibili.com/video/* // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/576413/B%E7%AB%99%E9%9F%B3%E9%A2%91%E4%B8%80%E9%94%AE%E4%B8%8B%E8%BD%BD.user.js // @updateURL https://update.greasyfork.icu/scripts/576413/B%E7%AB%99%E9%9F%B3%E9%A2%91%E4%B8%80%E9%94%AE%E4%B8%8B%E8%BD%BD.meta.js // ==/UserScript== (function() { 'use strict'; // 精致小巧,代码之美 const btn = document.createElement("button"); btn.style.cssText = "position:fixed;top:10%;right:5%;z-index:999999; width:30px;height:30px;border-radius:15px; border:1px solid blue"; document.body.appendChild(btn); // 点击下载逻辑(这里包一层注入) btn.onclick = function() { const script = document.createElement('script'); script.textContent = ` (async function(){ try { const audioUrl = window.__playinfo__.data.dash.audio[0].backupUrl[0]; const title = document.querySelector("#viewbox_report > div.video-info-title > div > h1").title; alert(\`开始下载:\${title}\`); const response = await fetch(audioUrl, { headers: { 'User-Agent': navigator.userAgent, 'Referer': 'https://www.bilibili.com/' } }); const blob = await response.blob(); const a = document.createElement('a'); const url = URL.createObjectURL(blob); a.href = url; a.download = \`\${title}.mp3\`; a.click(); setTimeout(() => URL.revokeObjectURL(url), 1000); } catch (err) { alert('下载失败:' + err); } })(); `; document.head.appendChild(script); script.remove(); }; })();