From 9571e986715ddc046f535df2a38050169a3b642b Mon Sep 17 00:00:00 2001 From: sienori Date: Sat, 23 Feb 2019 03:53:34 +0900 Subject: [PATCH] Do not show button when symbol is selected --- src/content/components/TranslateContainer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/content/components/TranslateContainer.js b/src/content/components/TranslateContainer.js index 8ca41a2..1f08fbd 100644 --- a/src/content/components/TranslateContainer.js +++ b/src/content/components/TranslateContainer.js @@ -48,7 +48,13 @@ const matchesTargetLang = async selectedText => { //先頭100字を翻訳にかけて判定 const partSelectedText = selectedText.substring(0, 100); const result = await translateText(partSelectedText); - const matchsLangs = targetLang === result.sourceLanguage && result.percentage > 0; + const isError = result.statusText !== "OK"; + if (isError) return false; + + const isNotText = result.percentage === 0; + if (isNotText) return true; + + const matchsLangs = targetLang === result.sourceLanguage; return matchsLangs; };