From e7812ac589b7b64760fb357b52aeae583571e550 Mon Sep 17 00:00:00 2001 From: wareya Date: Tue, 14 May 2019 00:36:13 -0400 Subject: [PATCH] don't fall back to json dict for text that only contains latin-1 --- background-script.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/background-script.js b/background-script.js index e79b456..a0033ba 100644 --- a/background-script.js +++ b/background-script.js @@ -140,11 +140,21 @@ function json_lookup_arbitrary_as_is(dict, text) } function json_dict_any_as_is(text) { - for(let dict of json_dicts) + let maybe_found_non_latin = false; + for(let i = 0; i < text.length; i++) { - let ret = json_lookup_arbitrary_as_is(dict, text); - if(ret !== undefined) - return ret; + let codepoint = text.codePointAt(i); + if(codepoint > 0x100) + maybe_found_non_latin = true; + } + if(maybe_found_non_latin) + { + for(let dict of json_dicts) + { + let ret = json_lookup_arbitrary_as_is(dict, text); + if(ret !== undefined) + return ret; + } } return undefined; }