Add waiting time option

This commit is contained in:
sienori 2018-07-31 23:02:29 +09:00
parent d3bcce91b6
commit bb6bf77df7
3 changed files with 43 additions and 2 deletions

View file

@ -86,6 +86,16 @@
"secondTargetLangCaptionLabel": {
"message": "Select the second target language."
},
"waitTimeLabel": {
"message": "Waiting time to translate"
},
"waitTimeCaptionLabel": {
"message":
"Specify the waiting time from the input of a character to the start of translation. (millisecond)"
},
"waitTime2CaptionLabel": {
"message": "If you translate it many times in a short time, it may become unusable for a while."
},
"menuLabel": {
"message": "Context menu"

View file

@ -170,6 +170,22 @@
</div>
</li>
</ul>
<hr>
<li class="optionContainer new">
<div class=optionText>
<p class=waitTimeLabel>翻訳までの待ち時間</p>
<p class="caption waitTimeCaptionLabel">文字が入力されてから翻訳を開始するまでの待ち時間を指定します。(ミリ秒)</p>
<p class="caption waitTime2CaptionLabel">短時間に何回も翻訳すると,しばらくの間利用できなくなることがあります。</p>
</div>
<div class=optionForm>
<label>
<input id=waitTime class=saveByChange type=number value=500 min=0 placeholder=500>
</label>
</div>
</li>
</ul>
</li>

View file

@ -124,7 +124,8 @@ textarea.addEventListener("paste", resize);
textarea.addEventListener("keydown", resize);
textarea.addEventListener("keyup", function(event) {
//if (event.keyCode == 13) resize();
if (sourceWord == textarea.value) return;
resize();
inputText();
});
@ -145,9 +146,23 @@ function textAreaClick() {
textarea.select();
}
let inputTimer;
//文字入力時の処理
async function inputText() {
function inputText() {
sourceWord = textarea.value;
const waitTime = S.get().waitTime;
clearTimeout(inputTimer);
inputTimer = setTimeout(() => {
runTranslation();
}, waitTime);
}
async function runTranslation() {
if (sourceWord == "") {
showResult("", "");
return;
}
const resultData = await T.translate(sourceWord, "auto", langList.value);
changeSecondLang(defaultTargetLang, resultData.sourceLanguage, resultData.percentage);