WIP
This commit is contained in:
parent
7598de2234
commit
dab46eda3e
@ -2,14 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<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.min.css">
|
||||||
<link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@ -19,21 +14,6 @@
|
|||||||
|
|
||||||
<p>Thank you for downloading this extension! I sincerely hope that it will assist you on your language learning journey.</p>
|
<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>
|
<div>
|
||||||
<h2>Quick Guide</h2>
|
<h2>Quick Guide</h2>
|
||||||
|
|
||||||
@ -51,8 +31,5 @@
|
|||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="../lib/jquery-2.2.2.min.js"></script>
|
|
||||||
<script src="js/import.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -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();
|
|
||||||
});
|
|
@ -25,54 +25,20 @@ class Translator {
|
|||||||
this.deinflector = new Deinflector();
|
this.deinflector = new Deinflector();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadData(callback) {
|
prepare() {
|
||||||
if (this.loaded) {
|
if (this.loaded) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadJsonInt('bg/data/rules.json').then(rules => {
|
const promises = [
|
||||||
|
loadJsonInt('bg/data/rules.json'),
|
||||||
|
loadJsonInt('bg/data/tags.json'),
|
||||||
|
this.database.prepare()
|
||||||
|
];
|
||||||
|
|
||||||
|
return Promise.all(promises).then(([rules, tags]) => {
|
||||||
this.deinflector.setRules(rules);
|
this.deinflector.setRules(rules);
|
||||||
return loadJsonInt('bg/data/tags.json');
|
this.tagMeta = tags;
|
||||||
}).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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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(() => {
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ class Yomichan {
|
|||||||
this.translator = new Translator();
|
this.translator = new Translator();
|
||||||
this.anki = new AnkiNull();
|
this.anki = new AnkiNull();
|
||||||
this.options = null;
|
this.options = null;
|
||||||
this.importTabId = null;
|
|
||||||
this.setState('disabled');
|
this.setState('disabled');
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
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) {
|
onMessage(request, sender, callback) {
|
||||||
const {action, params} = request, method = this['api_' + action];
|
const {action, params} = request, method = this['api_' + action];
|
||||||
|
|
||||||
@ -91,7 +76,7 @@ class Yomichan {
|
|||||||
break;
|
break;
|
||||||
case 'loading':
|
case 'loading':
|
||||||
chrome.browserAction.setBadgeText({text: '...'});
|
chrome.browserAction.setBadgeText({text: '...'});
|
||||||
this.translator.loadData(this.onImport.bind(this)).then(() => this.setState('enabled'));
|
this.translator.prepare().then(this.setState('enabled'));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user