+
16
-

回答

直接使用油猴脚本来提取音频,主要捕获通过 new Audio在js中直接播放url声音的网页,效果如下,点击即可下载本地:

800_auto

// ==UserScript==
// @name         Advanced Audio URL Catcher (JS Hook)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Hooks the Audio() constructor and <audio>.src setter to capture dynamically played audio URLs and provides download links.
// @author       YourName
// @match        *://*/*
// @grant        GM_download
// @grant        GM_log
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // --- 配置 ---
    // 设置要忽略的URL模式(例如,短的提示音或广告)
    const IGNORE_PATTERNS = [
        /ad-sound\.mp3/i, // 忽略广告声音
        /\.wav$/i,         // 忽略 .wav 文件
        /notification\.mp3/i // 忽略通知音
    ];

    // 使用 Set 来存储已捕获的URL,自动处理重复项
    const capturedUrls = new Set();
    let panel = null;

    // --- 核心功能:捕获并显示URL ---
    function captureUrl(url) {
        // 1. 过滤无效或不想要的URL
        if (!url || typeof url !== 'string' || url.startsWith('blob:') || url.startsWith('data:')) {
            return;
        }

        // 2. 检查是否已捕获
        if (capturedUrls.has(url)) {
            return;
        }

        // 3. 检查是否匹配忽略列表
        for (const pattern of IGNORE_PATTERNS) {
            if (pattern.test(url)) {
                GM_log(`Ignored audio URL by pattern: ${url}`);
                return;
            }
        }

        // 4. 确认捕获
        GM_log(`Captured audio URL: ${url}`);
        capturedUrls.add(url);
        displayUrl(url);
    }

    // --- UI部分:创建和更新悬浮面板 ---
    function createPanel() {
        if (document.getElementById('audio-catcher-panel')) {
            return;
        }
        panel = document.createElement('div');
        panel.id = 'audio-catcher-panel';
        panel.style.position = 'fixed';
        panel.style.bottom = '10px';
        panel.style.right = '10px';
        panel.style.width = '300px';
        panel.style.maxHeight = '400px';
        panel.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
        panel.style.color = 'white';
        panel.style.border = '1px solid #444';
        panel.style.borderRadius = '8px';
        panel.style.zIndex = '99999';
        panel.style.overflowY = 'auto';
        panel.style.fontSize = '12px';
        panel.style.fontFamily = 'sans-serif';
        panel.style.padding = '5px';

        const header = document.createElement('div');
        header.innerHTML = '<strong>音频捕获器</strong> (点击下载)';
        header.style.padding = '5px';
        header.style.textAlign = 'center';
        header.style.borderBottom = '1px solid #555';

        panel.appendChild(header);
        document.body.appendChild(panel);
    }

    function displayUrl(url) {
        if (!panel) {
            createPanel();
        }

        const item = document.createElement('div');
        item.style.padding = '8px';
        item.style.borderBottom = '1px solid #333';
        item.style.cursor = 'pointer';
        item.style.wordBreak = 'break-all';
        item.title = `点击下载: ${url}`;

        // 尝试从URL中提取文件名
        let filename = 'audio.mp3';
        try {
            const urlObj = new URL(url);
            filename = urlObj.pathname.split('/').pop() || filename;
        } catch (e) {
            // 如果URL无效,则使用基本提取
            filename = url.substring(url.lastIndexOf('/') + 1);
        }

        item.textContent = `					

网友回复

我知道答案,我要回答