划词朗读V1.5版

2018-07-16 23:30:23 -0400

* 设置全局

(function (){

if(document.getElementById('muttsread0')){

                    }

else{

var num1;

function getResult1(words) {

var spd=5; //默认语速为5,数字越大语速越快,可自行修改

var per=4;

//语调或语声,默认为4,可修改为1到6

var vol=5;

if(words.length>0){ try{

    words=words.replace(/\r\n/g,"")    

    words=words.replace(/\n/g,"");   

}catch(e) {    

}    

var vcurrent = document.getElementsByTagName('body')[0];

var newNodeTop; var n = 1600;

if(/.[\u4e00-\u9fa5]+.$/.test(words)) {

n=500; }

var num=0;

num1=0; for (var i = 0, l = words.length; i < l/n; i++) { var a = words.slice(ni, n(i+1)); num++;

num1++;

        newNodeTop = document.createElement("audio");
        newNodeTop.id="muttsread"+i;

newNodeTop.setAttribute("controls",""); //newNodeTop.setAttribute("autoplay","autoplay");

a=encodeURIComponent(a) ;

newNodeTop.setAttribute("src","http://tts.baidu.com/text2audio?idx=1&cuid=baidu_speech_demo&cod=5&lan=zh&ctp=1&pdt=1&spd="+spd+"&vol="+vol+"&pit=3&per="+per+"&tex="+a);

vcurrent.parentNode.insertBefore(newNodeTop, vcurrent);

} window.scrollTo(0, 0);

if(num>1){ try{ var str="\u5df2\u5206\u4e3a\u8bed\u97f3\u6bb5\u6570";

window.mx_browser_obj.showtip(unescape(str.replace(/\u/g, '%u'))+num);

}catch(e) {    

}    

}

}

        }

    var transBtn= document.createElement('span');        

var str1="\u8bfb";

transBtn.innerHTML = ''+unescape(str1.replace(/\\u/g, '%u'));                

transBtn.id='myTransBtn1'; var c = 'display:block!important;text-align:center;color:#fff;font-size:4vw;opacity:0.3;background:rgba(0, 0, 0, 0.9);border-radius:5px 0 0 5px;cursor:pointer;position:fixed;bottom:10%;width:10vw;height:7vw;right:0px;z-index:9999'; transBtn.style.cssText = c; transBtn.addEventListener('click', function () {
transBtn.style.display = "none";

}, false);
transBtn.style.display = "none";

document.body.appendChild(transBtn);

        //监听复制文本事件
        var lastText;
        var isClickTransBtn;

        document.addEventListener("selectionchange", function (e1) {

    var text = window.getSelection().toString().trim();
    if(!!text){
                transBtn.style.display = "block";
                lastText = text;
                transBtn.ontouchstart = function () {
                        return isClickTransBtn = true;
                }
            }else{
                if(!!isClickTransBtn){
                    isClickTransBtn = false;

                    if(document.getElementById('muttsread0')){

for(var j=0;j<num1;j++){

document.getElementsByTagName('html')[0].removeChild(document.getElementById('muttsread'+j));

}

                    }
                    getResult1(lastText);
                    transBtn.style.display = "none";
                }else{
                    transBtn.style.display = "none";
                }
            }
}, false);

}

})();

«Newer      Older»
Comment:
Name:

Back to home

Subscribe | Register | Login | N