BiliTran

attempt to translate Simplified Chinese to English on bilibili.com using Google Translate API

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         BiliTran
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  attempt to translate Simplified Chinese to English on bilibili.com using Google Translate API
// @author       mastodonna233
// @match        https://www.bilibili.com/
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    var audioElements = document.querySelectorAll('audio');
    
    // Loop through all audio elements on the page
    audioElements.forEach(function(audioElement) {
        // Get the language code for Simplified Chinese (zh-CN)
        var languageCode = 'zh-CN';
        
        // Create a new translation object using the Google Translate API
        var translation = new google.translate.Translation();
        
        // Set the source language to Simplified Chinese (zh-CN)
        translation.setSourceLanguage(languageCode);
        
        // Set the destination language to English (en)
        translation.setDestinationLanguage('en');
        
        // Get the audio element's text content
        var textContent = audioElement.textContent;
        
        // Translate the text using the Google Translate API
        translation.translateText(textContent, function(translatedText) {
            // Replace the original text with the translated text
            audioElement.textContent = translatedText;
        }, {
            // Use the "male" voice for the translation
            voice: 'male',
            
            // Set the pitch and speed of the voice
            pitch: 1,
            speed: 1
        });
    });
})();