From 4a6055d781cd9bafb1887ef4e8ee26d3735ad405 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 7 May 2016 18:24:31 -0700 Subject: WIP --- ext/bg/js/options-form.js | 12 +++++++----- ext/bg/js/options.js | 7 ++++--- ext/bg/js/translator.js | 21 ++++++++++++++------- ext/bg/js/yomichan.js | 8 ++++++-- ext/bg/options.html | 12 ++++++++++-- 5 files changed, 41 insertions(+), 19 deletions(-) (limited to 'ext') diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index eb9d2f53..422b9b4a 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -18,18 +18,20 @@ function optionsToForm(opts) { + $('#activateOnStartup').prop('checked', opts.activateOnStartup); $('#enableAnkiConnect').prop('checked', opts.enableAnkiConnect); - $('#selectMatchedText').prop('checked', opts.selectMatchedText); - $('#loadOnStartup').prop('checked', opts.loadOnStartup); + $('#loadEnamDict').prop('checked', opts.loadEnamDict); $('#scanLength').val(opts.scanLength); + $('#selectMatchedText').prop('checked', opts.selectMatchedText); } function formToOptions() { return sanitizeOptions({ - loadOnStartup: $('#loadOnStartup').prop('checked'), - selectMatchedText: $('#selectMatchedText').prop('checked'), + activateOnStartup: $('#activateOnStartup').prop('checked'), enableAnkiConnect: $('#enableAnkiConnect').prop('checked'), - scanLength: $('#scanLength').val() + loadEnamDict: $('#loadEnamDict').prop('checked'), + scanLength: $('#scanLength').val(), + selectMatchedText: $('#selectMatchedText').prop('checked') }); } diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index c73bc4c0..639644f7 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -19,10 +19,11 @@ function sanitizeOptions(options) { const defaults = { - loadOnStartup: false, - selectMatchedText: true, + activateOnStartup: false, enableAnkiConnect: false, - scanLength: 20 + loadEnamDict: false, + scanLength: 20, + selectMatchedText: true }; for (const key in defaults) { diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 1a7b9bb4..30bc92c1 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -33,14 +33,19 @@ class Translator { this.deinflector = new Deinflector(); } - loadData(callback) { + loadData({loadEnamDict=true}, callback) { if (this.loaded) { callback(); return; } + let files = ['rules', 'tags', 'edict', 'kanjidic']; + if (loadEnamDict) { + files = files.concat('enamdict'); + } + const pendingLoads = []; - for (const key of ['rules', 'tags', 'edict', 'enamdict', 'kanjidic']) { + for (const key of files) { pendingLoads.push(key); Translator.loadData(this.paths[key], (response) => { switch (key) { @@ -82,10 +87,12 @@ class Translator { return tags; }); - if (dfs !== null) { - for (const df of dfs) { - this.processTerm(groups, df.source, df.tags, df.rules, df.root); - } + if (dfs === null) { + continue; + } + + for (const df of dfs) { + this.processTerm(groups, df.source, df.tags, df.rules, df.root); } } @@ -131,7 +138,7 @@ class Translator { } findKanji(text) { - let definitions = []; + let definitions = []; const processed = {}; for (const c of text) { diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index abbcefe4..ca53ebf9 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -43,7 +43,7 @@ class Yomichan { chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); chrome.browserAction.onClicked.addListener(this.onBrowserAction.bind(this)); - if (this.options.loadOnStartup) { + if (this.options.activateOnStartup) { this.setState('loading'); } }); @@ -52,6 +52,7 @@ class Yomichan { onMessage(request, sender, callback) { const {action, params} = request, handlers = { canAddNotes: ({definitions, modes}) => this.ankiInvoke('canAddNotes', {definitions: definitions, modes: modes}, 'notes', callback), + addNote: ({definition, mode}) => this.ankiInvoke('addNote', {definition: definition, mode: mode}, null, callback), findKanji: (text) => callback(this.translator.findKanji(text)), findTerm: (text) => callback(this.translator.findTerm(text)), getOptions: () => callback(this.options), @@ -90,7 +91,10 @@ class Yomichan { break; case 'loading': chrome.browserAction.setBadgeText({text: '...'}); - this.translator.loadData(() => this.setState('enabled')); + this.translator.loadData( + {loadEnamDict: this.options.loadEnamDict}, + () => this.setState('enabled') + ); break; } diff --git a/ext/bg/options.html b/ext/bg/options.html index a89a546d..29938fa5 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -23,7 +23,15 @@
- + +
+
+
+ +
+
+
+
@@ -39,7 +47,7 @@
- +
-- cgit v1.2.3