From dab46eda3e42e5f0a624bb285a555b078b999a99 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 13 Nov 2016 11:58:23 -0800 Subject: WIP --- ext/bg/guide.html | 35 +++++++++++++++++++++++++++++ ext/bg/import.html | 58 ------------------------------------------------- ext/bg/js/import.js | 36 ------------------------------ ext/bg/js/translator.js | 52 ++++++++------------------------------------ ext/bg/js/yomichan.js | 17 +-------------- 5 files changed, 45 insertions(+), 153 deletions(-) create mode 100644 ext/bg/guide.html delete mode 100644 ext/bg/import.html delete mode 100644 ext/bg/js/import.js diff --git a/ext/bg/guide.html b/ext/bg/guide.html new file mode 100644 index 00000000..e5ec59d7 --- /dev/null +++ b/ext/bg/guide.html @@ -0,0 +1,35 @@ + + + + + Yomichan + + + + +
+ + +

Thank you for downloading this extension! I sincerely hope that it will assist you on your language learning journey.

+ +
+

Quick Guide

+ +

+ Please read the steps outlined below to get quickly get up and running with Yomichan. For complete documentation, + visit the official homepage. +

+ +
    +
  1. Left-click on the icon to enable or disable Yomichan for the current browser instance.
  2. +
  3. Right-click on the icon and select Options to open the Yomichan options page.
  4. +
  5. Hold down Shift (or the middle mouse button) as you hover over text to see term definitions.
  6. +
  7. Resize the definitions window by dragging the bottom-left corner inwards or outwards.
  8. +
  9. Click on Kanji in the definition window to view additional information about that character.
  10. +
+
+
+ + diff --git a/ext/bg/import.html b/ext/bg/import.html deleted file mode 100644 index c2e9682e..00000000 --- a/ext/bg/import.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - - Yomichan Dictionary Import - - - - - -
- - -

Thank you for downloading this extension! I sincerely hope that it will assist you on your language learning journey.

- -
-

Dictionary Import

- -

- Before it can be used for the first time, Yomichan must import the Japanese dictionary data included with this extension. This process can take a - couple of minutes to finish so please be patient! Please do not completely exit out of your browser until this process completes. -

- -
-
-
- -
Dictionary import complete!
-
- -
-

Quick Guide

- -

- Please read the steps outlined below to get quickly get up and running with Yomichan. For complete documentation, - visit the official homepage. -

- -
    -
  1. Left-click on the icon to enable or disable Yomichan for the current browser instance.
  2. -
  3. Right-click on the icon and select Options to open the Yomichan options page.
  4. -
  5. Hold down Shift (or the middle mouse button) as you hover over text to see term definitions.
  6. -
  7. Resize the definitions window by dragging the bottom-left corner inwards or outwards.
  8. -
  9. Click on Kanji in the definition window to view additional information about that character.
  10. -
-
-
- - - - - diff --git a/ext/bg/js/import.js b/ext/bg/js/import.js deleted file mode 100644 index 0601cb9f..00000000 --- a/ext/bg/js/import.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2016 Alex Yatskov - * Author: Alex Yatskov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -function api_setProgress(progress) { - $('.progress-bar').css('width', `${progress}%`); - - if (progress === 100.0) { - $('.progress').hide(); - $('.alert').show(); - } -} - -chrome.runtime.onMessage.addListener(({action, params}, sender, callback) => { - const method = this['api_' + action]; - if (typeof(method) === 'function') { - method.call(this, params); - } - - callback(); -}); diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index ed8c720b..01213bed 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -25,54 +25,20 @@ class Translator { this.deinflector = new Deinflector(); } - loadData(callback) { + prepare() { if (this.loaded) { return Promise.resolve(); } - return loadJsonInt('bg/data/rules.json').then(rules => { - this.deinflector.setRules(rules); - return loadJsonInt('bg/data/tags.json'); - }).then(tagMeta => { - this.tagMeta = tagMeta; - return this.database.prepare(); - }).then(exists => { - if (exists) { - return; - } - - if (callback) { - callback({state: 'begin', progress: 0}); - } - - const banks = {}; - const bankCallback = (total, loaded, indexUrl) => { - banks[indexUrl] = {loaded, total}; - - let percent = 0.0; - for (const url in banks) { - percent += banks[url].loaded / banks[url].total; - } + const promises = [ + loadJsonInt('bg/data/rules.json'), + loadJsonInt('bg/data/tags.json'), + this.database.prepare() + ]; - percent /= 3.0; - - if (callback) { - callback({state: 'update', progress: Math.ceil(100.0 * percent)}); - } - }; - - return Promise.all([ - this.database.importDictionary(chrome.extension.getURL('bg/data/edict/index.json'), bankCallback), - this.database.importDictionary(chrome.extension.getURL('bg/data/enamdict/index.json'), bankCallback), - this.database.importDictionary(chrome.extension.getURL('bg/data/kanjidic/index.json'), bankCallback), - ]).then(() => { - return this.database.seal(); - }).then(() => { - if (callback) { - callback({state: 'end', progress: 100.0}); - } - }); - }).then(() => { + return Promise.all(promises).then(([rules, tags]) => { + this.deinflector.setRules(rules); + this.tagMeta = tags; this.loaded = true; }); } diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index d471add4..62b6c7b1 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -25,7 +25,6 @@ class Yomichan { this.translator = new Translator(); this.anki = new AnkiNull(); this.options = null; - this.importTabId = null; this.setState('disabled'); chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); @@ -39,20 +38,6 @@ class Yomichan { }); } - onImport({state, progress}) { - if (state === 'begin') { - chrome.tabs.create({url: chrome.extension.getURL('bg/import.html')}, tab => this.importTabId = tab.id); - } - - if (this.importTabId !== null) { - this.tabInvoke(this.importTabId, 'setProgress', progress); - } - - if (state === 'end') { - this.importTabId = null; - } - } - onMessage(request, sender, callback) { const {action, params} = request, method = this['api_' + action]; @@ -91,7 +76,7 @@ class Yomichan { break; case 'loading': chrome.browserAction.setBadgeText({text: '...'}); - this.translator.loadData(this.onImport.bind(this)).then(() => this.setState('enabled')); + this.translator.prepare().then(this.setState('enabled')); break; } -- cgit v1.2.3