From b48debd84c91fc43bdbbdde6e9bc3b97e9c13e9b Mon Sep 17 00:00:00 2001 From: example Date: Sat, 30 Mar 2019 08:39:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E5=A4=8D=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E9=9F=B3=E9=A2=91=E8=A7=A6=E5=8F=91=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- translate/translate-dictionary.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/translate/translate-dictionary.js b/translate/translate-dictionary.js index 1771d2d..fafe748 100644 --- a/translate/translate-dictionary.js +++ b/translate/translate-dictionary.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 划词翻译:多词典查询 // @namespace http://tampermonkey.net/ -// @version 3.8 +// @version 3.9 // @description 划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、剑桥高阶、沪江小D、谷歌翻译” // @author https://github.com/barrer // @match http://*/* @@ -128,7 +128,7 @@ // 发音引擎 var audioEngines = []; // [{name: 'abc', url: 'http://*.mp3', ...}, ...] // 发音缓存 - var audioCache = {}; // {'mp3 download url': Audio} + var audioCache = {}; // {'mp3 download url': blob} // 翻译引擎结果集 var engineResult = {}; // id: DOM // ID 类别 @@ -756,21 +756,22 @@ } /**发音*/ function play(obj) { + var audio = new iframeWin.Audio(); if (obj.url in audioCache) { // 查找缓存 log('audio in cache', obj, audioCache); - audioCache[obj.url].play(); - return; - } - var audio = new iframeWin.Audio(); - ajax(obj.url, function (rst, res) { - audio.src = createObjectURLWithTry(res.response); - audioCache[obj.url] = audio; // 放入缓存 + audio.src = createObjectURLWithTry(audioCache[obj.url]); audio.play(); // 播放 - }, function (rst) { - log(rst); - }, { - responseType: 'blob' - }); + } else { + ajax(obj.url, function (rst, res) { + audio.src = createObjectURLWithTry(res.response); + audioCache[obj.url] = res.response; // 放入缓存 + audio.play(); // 播放 + }, function (rst) { + log(rst); + }, { + responseType: 'blob' + }); + } } /**得到发音按钮*/ function getPlayButton(obj) {