VoiceDeOChat

OGARio-chat with voice

目前為 2017-06-26 提交的版本,檢視 最新版本

// ==UserScript==
// @name         VoiceDeOChat
// @namespace    VoiceDeOChat.v0
// @version      0.1.2
// @description  OGARio-chat with voice
// @description:ja OGARio のチャットを音声入力で行えるようにします
// @author       tannichi
// @match        http://agar.io/*
// ==/UserScript==

(function() {
    'use strict';
    function pre_loop(){
        // この時点では jQuery は使えない
        if(! document.getElementById("message-box")){
            setTimeout(pre_loop, 1000);
            console.log("VoiceDeOChat:wait for OGARio load");
            return;
        }
        return initialize();
    }
    return pre_loop();
    function initialize(){
        $("#message-box").click(function(){return false;});
        $("#message-menu").append('<a href="#" class="chatbox-hide icon-close" style="float:right;">X</a>');
        $(".chatbox-hide").click(function(){
            $("#message-box").css("display", "none");
            return false;
        });
        $("#message-menu").append('<a href="#" class="chatbox-clear icon-clear" style="float:right;">C</a>');
        $(".chatbox-clear").click(function(){
            $("#message").val("");
            return false;
        });
        window.SpeechRecognition = window.SpeechRecognition || webkitSpeechRecognition;
        var recognition = new window.SpeechRecognition();
        recognition.addEventListener('result', function(event){
            var text_to = event.results.item(0).item(0).transcript;
            var text_pre = $("#message").val();
            if(text_pre === ""){
                text_to = "?" + text_to;
            }else{
                text_to = text_pre + " " + text_to;
            }
            $("#message").val(text_to);
        }, false);
        $("#message-menu").append('<a href="#" class="voice-start icon-mic" style="float:right;">?</a>');
        $(".voice-start").click(function(){
            recognition.start();
            return false;
        });
    }

    // Your code here...
})();