From e661c4bd4383816f3f14c7458944795b44a40bad Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 22 Apr 2017 13:02:06 -0700 Subject: add option to disable searching of alphanumeric text, fixes #47 --- ext/bg/js/util.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'ext/bg/js/util.js') diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 64143ffe..09337c63 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -30,6 +30,20 @@ function promiseCallback(promise, callback) { } +/* + * Japanese + */ + +function jpIsKanji(c) { + const code = c.charCodeAt(0); + return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0; +} + +function jpIsKana(c) { + return wanakana.isKana(c); +} + + /* * Commands */ @@ -98,6 +112,7 @@ function optionsSetDefaults(options) { middleMouse: true, selectText: true, imposter: true, + alphanumeric: true, delay: 15, length: 10 }, @@ -489,14 +504,9 @@ function jsonLoadDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { */ function handlebarsKanjiLinks(options) { - const isKanji = c => { - const code = c.charCodeAt(0); - return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0; - }; - let result = ''; for (const c of options.fn(this)) { - if (isKanji(c)) { + if (jpIsKanji(c)) { result += `${c}`; } else { result += c; -- cgit v1.2.3