Greasy Fork

Greasy Fork is available in English.

王者荣耀音频下载命名

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

当前为 2023-12-02 提交的版本,查看 最新版本

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

(function() {
    'use strict';

    function downloadAudio(mp3URL, speechText, index) {
        const xhr = new XMLHttpRequest();
        xhr.open('GET', mp3URL, true);
        xhr.responseType = 'blob';

        xhr.onload = function() {
            if (xhr.status === 200) {
                const blob = xhr.response;
                const link = document.createElement('a');
                link.href = window.URL.createObjectURL(blob);
                link.download = `${index + 1}_${speechText}.mp3`;
                link.click();
            } else {
                console.error('Error downloading audio:', xhr.statusText);
            }
        };

        xhr.onerror = function() {
            console.error('Network error while downloading audio');
        };

        xhr.send();
    }

    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 = 'Download All Audio';
    downloadAllButton.style.position = 'fixed';
    downloadAllButton.style.top = '10px';
    downloadAllButton.style.left = '10px';
    downloadAllButton.style.zIndex = '999'; // 添加 z-index
    downloadAllButton.addEventListener('click', autoDownloadAudio);

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