diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/background.html | 1 | ||||
-rw-r--r-- | ext/bg/js/options.js | 8 | ||||
-rw-r--r-- | ext/bg/js/popup.js | 2 | ||||
-rw-r--r-- | ext/bg/js/yomichan.js | 79 | ||||
-rw-r--r-- | ext/fg/js/display-frame.js | 40 | ||||
-rw-r--r-- | ext/fg/js/driver.js | 12 | ||||
-rw-r--r-- | ext/mixed/js/display.js | 8 |
7 files changed, 79 insertions, 71 deletions
diff --git a/ext/bg/background.html b/ext/bg/background.html index 3c7b0dd9..1aa60559 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -5,7 +5,6 @@ <script src="/mixed/lib/dexie.min.js"></script> <script src="/mixed/lib/wanakana.min.js"></script> <script src="/bg/js/templates.js"></script> - <script src="/bg/js/gecko.js"></script> <script src="/bg/js/util.js"></script> <script src="/bg/js/anki-connect.js"></script> <script src="/bg/js/anki-null.js"></script> diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 565ccd41..f06cc056 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -189,7 +189,7 @@ function onDictionaryPurge(e) { options.dictionaries = {}; return optionsSave(options).then(() => { populateDictionaries(options); - instYomi().setOptions(options); + instYomi().optionsSet(options); }); }); } @@ -208,7 +208,7 @@ function onDictionaryImport() { optionsLoad().then(options => { instDb().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => { options.dictionaries[summary.title] = {enabled: true, priority: 0}; - return optionsSave(options).then(() => instYomi().setOptions(options)); + return optionsSave(options).then(() => instYomi().optionsSet(options)); }).then(() => populateDictionaries(options)).catch(showDictionaryError).then(() => { showDictionarySpinner(false); dictProgress.hide(); @@ -339,7 +339,7 @@ function onAnkiModelChanged(e) { optionsNew.anki[tabId].fields = {}; populateAnkiFields(element, optionsNew).then(() => { - optionsSave(optionsNew).then(() => instYomi().setOptions(optionsNew)); + optionsSave(optionsNew).then(() => instYomi().optionsSet(optionsNew)); }).catch(showAnkiError).then(() => showAnkiSpinner(false)); }); } @@ -351,7 +351,7 @@ function onOptionsChanged(e) { getFormData().then(({optionsNew, optionsOld}) => { return optionsSave(optionsNew).then(() => { - instYomi().setOptions(optionsNew); + instYomi().optionsSet(optionsNew); updateVisibility(optionsNew); const ankiUpdated = diff --git a/ext/bg/js/popup.js b/ext/bg/js/popup.js index 0d1fb04e..37a76832 100644 --- a/ext/bg/js/popup.js +++ b/ext/bg/js/popup.js @@ -28,7 +28,7 @@ $(document).ready(() => { toggle.bootstrapToggle(); toggle.change(() => { options.general.enable = toggle.prop('checked'); - optionsSave(options).then(() => instYomi().setOptions(options)); + optionsSave(options).then(() => instYomi().optionsSet(options)); }); }); }); diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index f7bec615..37fe74ee 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -32,27 +32,10 @@ window.yomichan = new class { chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this)); } - this.translator.prepare().then(optionsLoad).then(this.setOptions.bind(this)); + this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this)); } - onInstalled(details) { - if (details.reason === 'install') { - chrome.tabs.create({url: chrome.extension.getURL('bg/guide.html')}); - } - } - - onMessage(request, sender, callback) { - const {action, params} = request, method = this['api_' + action]; - - if (typeof(method) === 'function') { - params.callback = callback; - method.call(this, params); - } - - return true; - } - - setOptions(options) { + optionsSet(options) { this.options = options; let usable = false; @@ -72,7 +55,7 @@ window.yomichan = new class { this.anki = new AnkiNull(); } - this.tabInvokeAll('setOptions', this.options); + this.tabInvokeAll('optionsSet', this.options); } tabInvokeAll(action, params) { @@ -83,7 +66,7 @@ window.yomichan = new class { }); } - formatNote(definition, mode) { + noteFormat(definition, mode) { const note = {fields: {}, tags: this.options.anki.tags}; let fields = []; @@ -145,7 +128,7 @@ window.yomichan = new class { } definitionAdd(definition, mode) { - const note = this.formatNote(definition, mode); + const note = this.noteFormat(definition, mode); return this.anki.addNote(note); } @@ -153,7 +136,7 @@ window.yomichan = new class { const notes = []; for (const definition of definitions) { for (const mode of modes) { - notes.push(this.formatNote(definition, mode)); + notes.push(this.noteFormat(definition, mode)); } } @@ -176,27 +159,45 @@ window.yomichan = new class { return Promise.resolve(Handlebars.templates[template](data)); } - api_optionsGet({callback}) { - promiseCallback(optionsLoad(), callback); + onInstalled(details) { + if (details.reason === 'install') { + chrome.tabs.create({url: chrome.extension.getURL('bg/guide.html')}); + } } - api_kanjiFind({text, callback}) { - promiseCallback(this.kanjiFind(text), callback); - } + onMessage(request, sender, callback) { + const handlers = new class { + api_optionsGet({callback}) { + promiseCallback(optionsLoad(), callback); + } - api_termsFind({text, callback}) { - promiseCallback(this.termsFind(text), callback); - } + api_kanjiFind({text, callback}) { + promiseCallback(this.kanjiFind(text), callback); + } - api_textRender({template, data, callback}) { - promiseCallback(this.textRender(template, data), callback); - } + api_termsFind({text, callback}) { + promiseCallback(this.termsFind(text), callback); + } - api_definitionAdd({definition, mode, callback}) { - promiseCallback(this.definitionAdd(definition, mode), callback); - } + api_textRender({template, data, callback}) { + promiseCallback(this.textRender(template, data), callback); + } - api_definitionsAddable({definitions, modes, callback}) { - promiseCallback(this.definitionsAddable(definitions, modes), callback); + api_definitionAdd({definition, mode, callback}) { + promiseCallback(this.definitionAdd(definition, mode), callback); + } + + api_definitionsAddable({definitions, modes, callback}) { + promiseCallback(this.definitionsAddable(definitions, modes), callback); + } + }; + + const {action, params} = request, method = handlers[`api_${action}`]; + if (typeof(method) === 'function') { + params.callback = callback; + method.call(this, params); + } + + return true; } }; diff --git a/ext/fg/js/display-frame.js b/ext/fg/js/display-frame.js index 16435a27..56b56861 100644 --- a/ext/fg/js/display-frame.js +++ b/ext/fg/js/display-frame.js @@ -41,31 +41,37 @@ window.displayFrame = new class extends Display { handleError(error) { if (window.orphaned) { - this.api_showOrphaned(); + this.showOrphaned(); } else { errorShow(error); } } - onMessage(e) { - const {action, params} = e.originalEvent.data, method = this['api_' + action]; - if (typeof(method) === 'function') { - method.call(this, params); - } + showOrphaned() { + $('#content').hide(); + $('#orphan').show(); } - api_showTermDefs({definitions, options, context}) { - window.scrollTo(0, 0); - super.showTermDefs(definitions, options, context); - } + onMessage(e) { + const handlers = new class { + api_showTermDefs({definitions, options, context}) { + window.scrollTo(0, 0); + this.showTermDefs(definitions, options, context); + } - api_showKanjiDefs({definitions, options, context}) { - window.scrollTo(0, 0); - super.showKanjiDefs(defintions, options, context); - } + api_showKanjiDefs({definitions, options, context}) { + window.scrollTo(0, 0); + this.showKanjiDefs(defintions, options, context); + } - api_showOrphaned() { - $('#content').hide(); - $('#orphan').show(); + api_showOrphaned() { + this.showOrphaned(); + } + }; + + const {action, params} = e.originalEvent.data, method = handlers[`api_${action}`]; + if (typeof(method) === 'function') { + method.call(this, params); + } } }; diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 73ddd84f..2cbe3e08 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -102,7 +102,13 @@ class Driver { } onBgMessage({action, params}, sender, callback) { - const method = this['api_' + action]; + const handlers = new class { + api_optionsSet(options) { + this.options = options; + } + }; + + const method = handlers[`api_${action}`]; if (typeof(method) === 'function') { method.call(this, params); } @@ -205,10 +211,6 @@ class Driver { errorShow(error); } } - - api_setOptions(options) { - this.options = options; - } } window.driver = new Driver(); diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 26d50862..c2382d43 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -67,13 +67,13 @@ class Display { this.textRender('terms.html', params).then(content => { this.container.html(content); $('.action-add-note').click(this.onActionAddNote.bind(this)); - $('.kanji-link').click(this.onKanjiSearch.bind(this)); $('.action-play-audio').click(this.onActionPlayAudio.bind(this)); + $('.kanji-link').click(e => this.onKanjiSearch(e, options)); return this.adderButtonsUpdate(['term_kanji', 'term_kana'], sequence); }).catch(this.handleError.bind(this)); } - showKanjiDefs({definitions, options, context}) { + showKanjiDefs(definitions, options, context) { const sequence = ++this.sequence; const params = { definitions, @@ -122,11 +122,11 @@ class Display { }); } - onKanjiSearch(e) { + onKanjiSearch(e, options) { e.preventDefault(); const character = $(e.target).text(); this.kanjiFind(character).then(definitions => { - this.api_showKanjiDefs({definitions, options, context}); + this.showKanjiDefs(definitions, options, context); }).catch(this.handleError.bind(this)); } |