Greasy Fork

王者荣耀音频下载命名

批量下载王者荣耀单英雄页面语音,文件用台词命名。

目前为 2023-12-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         王者荣耀音频下载命名
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  批量下载王者荣耀单英雄页面语音,文件用台词命名。
// @author       You
// @match        https://world.honorofkings.com/*
// @match        https://pvp.qq.com/ip/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=honorofkings.com
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    function downloadAudio(mp3URL, speechText, index) {
        fetch(mp3URL)
            .then(response => response.blob())
            .then(blob => {
                const link = document.createElement('a');
                link.href = window.URL.createObjectURL(blob);
                link.download = `${speechText}.mp3`;
                link.click();
            })
            .catch(error => console.error('Error downloading audio:', error));
    }

    function autoDownloadAudio() {
        const voiceItems = document.querySelectorAll('.dinfo-voice-item');

        voiceItems.forEach((voiceItem, index) => {
            const mp3URL = voiceItem.getAttribute('data-mp3');
            const speechText = voiceItem.querySelector('span').textContent.trim();

            // 下载音频文件
            downloadAudio(mp3URL, speechText, index);
        });
    }

    // 创建一键下载按钮
    const downloadAllButton = document.createElement('button');
    downloadAllButton.textContent = '下载该页面所有音频';
    downloadAllButton.style.position = 'fixed';
    downloadAllButton.style.top = '10px';
    downloadAllButton.style.left = '10px';
    downloadAllButton.style.zIndex = '999';
    downloadAllButton.addEventListener('click', autoDownloadAudio);

    // 将按钮添加到页面
    document.body.appendChild(downloadAllButton);
})();