diff options
| -rw-r--r-- | ext/bg/js/handlebars.js | 2 | ||||
| -rw-r--r-- | ext/bg/js/search.js | 2 | ||||
| -rw-r--r-- | ext/bg/js/translator.js | 3 | ||||
| -rw-r--r-- | ext/mixed/js/japanese.js | 51 | 
4 files changed, 6 insertions, 52 deletions
| diff --git a/ext/bg/js/handlebars.js b/ext/bg/js/handlebars.js index 6d1581be..62f89ee4 100644 --- a/ext/bg/js/handlebars.js +++ b/ext/bg/js/handlebars.js @@ -61,7 +61,7 @@ function handlebarsFuriganaPlain(options) {  function handlebarsKanjiLinks(options) {      let result = '';      for (const c of options.fn(this)) { -        if (jpIsKanji(c)) { +        if (jpIsCharCodeKanji(c.charCodeAt(0))) {              result += `<a href="#" class="kanji-link">${c}</a>`;          } else {              result += c; diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index ea68915c..f5c641a8 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -265,7 +265,7 @@ class DisplaySearch extends Display {                  text !== this.clipboardPreviousText              ) {                  this.clipboardPreviousText = text; -                if (jpIsAnyCharacterJapanese(text)) { +                if (jpIsStringPartiallyJapanese(text)) {                      this.setQuery(this.isWanakanaEnabled() ? window.wanakana.toKana(text) : text);                      window.history.pushState(null, '', `${window.location.pathname}?query=${encodeURIComponent(text)}`);                      this.onSearchQueryUpdated(this.query.value, true); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 2fb36194..cda1099f 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -590,8 +590,7 @@ class Translator {          if (!options.scanning.alphanumeric) {              const ii = text.length;              for (let i = 0; i < ii; ++i) { -                const c = text[i]; -                if (!jpIsCharacterJapanese(c)) { +                if (!jpIsCharCodeJapanese(text.charCodeAt(i))) {                      text = text.substring(0, i);                      break;                  } diff --git a/ext/mixed/js/japanese.js b/ext/mixed/js/japanese.js index 98ce9fc4..93366db0 100644 --- a/ext/mixed/js/japanese.js +++ b/ext/mixed/js/japanese.js @@ -162,52 +162,6 @@ function jpIsStringPartiallyJapanese(str) {  } -// Old character/string testing functions - -function jpIsKanji(c) { -    const code = c.charCodeAt(0); -    return ( -        (code >= 0x4e00 && code < 0x9fb0) || -        (code >= 0x3400 && code < 0x4dc0) -    ); -} - -function jpIsKana(c) { -    const code = c.charCodeAt(0); -    return ( -        (code >= 0x3041 && code <= 0x3096) || // hiragana -        (code >= 0x30a1 && code <= 0x30fc) // katakana -    ); -} - -function jpIsCharFullWidth(c) { -    const code = c.charCodeAt(0); -    return ( -        (code >= 0xff21 && code <= 0xff3a) || // full width upper case roman letters -        (code >= 0xff41 && code <= 0xff3a) || // full width upper case roman letters -        (code >= 0xff10 && code <= 0xff19) // full width numbers -    ); -} - -function jpIsKanaHalfWidth(c) { -    const code = c.charCodeAt(0); -    return (code >= 0xff66 && code <= 0xff9f); // half width katakana -} - -function jpIsCharacterJapanese(c) { -    return jpIsKanji(c) || jpIsKana(c) || jpIsCharFullWidth(c) || jpIsKanaHalfWidth(c); -} - -function jpIsAnyCharacterJapanese(text) { -    for (const c of text) { -        if (jpIsCharacterJapanese(c)) { -            return true; -        } -    } -    return false; -} - -  // Conversion functions  function jpKatakanaToHiragana(text) { @@ -250,7 +204,7 @@ function jpConvertReading(expressionFragment, readingFragment, readingMode) {              if (readingFragment) {                  return jpToRomaji(readingFragment);              } else { -                if (jpIsKana(expressionFragment)) { +                if (jpIsStringEntirelyKana(expressionFragment)) {                      return jpToRomaji(expressionFragment);                  }              } @@ -307,7 +261,8 @@ function jpDistributeFurigana(expression, reading) {      const groups = [];      let modePrev = null;      for (const c of expression) { -        const modeCurr = jpIsKanji(c) || c.charCodeAt(0) === 0x3005 /* noma */ ? 'kanji' : 'kana'; +        const charCode = c.charCodeAt(0); +        const modeCurr = jpIsCharCodeKanji(charCode) || charCode === JP_ITERATION_MARK_CHAR_CODE ? 'kanji' : 'kana';          if (modeCurr === modePrev) {              groups[groups.length - 1].text += c;          } else { |