diff options
-rw-r--r-- | ext/bg/guide.html (renamed from ext/bg/import.html) | 25 | ||||
-rw-r--r-- | ext/bg/js/import.js | 36 | ||||
-rw-r--r-- | ext/bg/js/translator.js | 52 | ||||
-rw-r--r-- | ext/bg/js/yomichan.js | 17 |
4 files changed, 11 insertions, 119 deletions
diff --git a/ext/bg/import.html b/ext/bg/guide.html index c2e9682e..e5ec59d7 100644 --- a/ext/bg/import.html +++ b/ext/bg/guide.html @@ -2,14 +2,9 @@ <html lang="en"> <head> <meta charset="UTF-8"> - <title>Yomichan Dictionary Import</title> + <title>Yomichan</title> <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css"> - <style> - div.alert { - display: none; - } - </style> </head> <body> <div class="container"> @@ -20,21 +15,6 @@ <p>Thank you for downloading this extension! I sincerely hope that it will assist you on your language learning journey.</p> <div> - <h2>Dictionary Import</h2> - - <p> - 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. - </p> - - <div class="progress"> - <div class="progress-bar progress-bar-striped" style="width: 0%"></div> - </div> - - <div class="alert alert-success">Dictionary import complete!</div> - </div> - - <div> <h2>Quick Guide</h2> <p> @@ -51,8 +31,5 @@ </ol> </div> </div> - - <script src="../lib/jquery-2.2.2.min.js"></script> - <script src="js/import.js"></script> </body> </html> 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 <alex@foosoft.net> - * Author: Alex Yatskov <alex@foosoft.net> - * - * 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 <http://www.gnu.org/licenses/>. - */ - - -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; } |