summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-04 18:24:57 -0800
committerAlex Yatskov <alex@foosoft.net>2017-03-04 18:24:57 -0800
commit30999c13d32e7f111db16814dc2cbb0f30825861 (patch)
tree3aa24f7045f10237aa744651844d18219d1890e6 /ext/bg
parentb039d300249087aee18c7e8565ae7447d2cf5b15 (diff)
wip
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/background.html1
-rw-r--r--ext/bg/js/options.js8
-rw-r--r--ext/bg/js/popup.js2
-rw-r--r--ext/bg/js/yomichan.js79
4 files changed, 45 insertions, 45 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;
}
};