More cleanup
This commit is contained in:
parent
22cbafb7b7
commit
809e4f855f
@ -50,9 +50,9 @@ class Yomichan {
|
|||||||
|
|
||||||
onMessage(request, sender, callback) {
|
onMessage(request, sender, callback) {
|
||||||
const {action, params} = request, handlers = {
|
const {action, params} = request, handlers = {
|
||||||
canAddNotes: ({definitions}) => this.ankiInvoke('canAddNotes', definitions, callback),
|
canAddNotes: (definitions) => this.ankiInvoke('canAddNotes', definitions, callback),
|
||||||
findKanji: ({text}) => callback(this.translator.findKanji(text)),
|
findKanji: (text) => callback(this.translator.findKanji(text)),
|
||||||
findTerm: ({text}) => callback(this.translator.findTerm(text)),
|
findTerm: (text) => callback(this.translator.findTerm(text)),
|
||||||
getOptions: () => callback(this.options),
|
getOptions: () => callback(this.options),
|
||||||
getState: () => callback(this.state),
|
getState: () => callback(this.state),
|
||||||
renderText: ({data, template}) => callback(Handlebars.templates[template](data))
|
renderText: ({data, template}) => callback(Handlebars.templates[template](data))
|
||||||
|
@ -21,30 +21,30 @@
|
|||||||
// Background APIs
|
// Background APIs
|
||||||
//
|
//
|
||||||
|
|
||||||
function sendMessage(action, params, callback) {
|
function bgSendMessage(action, params, callback) {
|
||||||
chrome.runtime.sendMessage({action: action, params: params}, callback);
|
chrome.runtime.sendMessage({action: action, params: params}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function findTerm(text, callback) {
|
function bgFindTerm(text, callback) {
|
||||||
sendMessage('findTerm', {text: text}, callback);
|
bgSendMessage('findTerm', text, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function findKanji(text, callback) {
|
function bgFindKanji(text, callback) {
|
||||||
sendMessage('findKanji', {text: text}, callback);
|
bgSendMessage('findKanji', text, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderText(data, template, callback) {
|
function bgRenderText(data, template, callback) {
|
||||||
sendMessage('renderText', {data: data, template: template}, callback);
|
bgSendMessage('renderText', {data: data, template: template}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOptions(callback) {
|
function bgGetOptions(callback) {
|
||||||
sendMessage('getOptions', null, callback);
|
bgSendMessage('getOptions', null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getState(callback) {
|
function bgGetState(callback) {
|
||||||
sendMessage('getState', null, callback);
|
bgSendMessage('getState', null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function canAddNotes(definitions, callback) {
|
function bgCanAddNotes(definitions, callback) {
|
||||||
sendMessage('canAddNotes', {definitions: definitions}, callback);
|
bgSendMessage('canAddNotes', definitions, callback);
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ class Client {
|
|||||||
window.addEventListener('scroll', (e) => this.hidePopup());
|
window.addEventListener('scroll', (e) => this.hidePopup());
|
||||||
window.addEventListener('resize', (e) => this.hidePopup());
|
window.addEventListener('resize', (e) => this.hidePopup());
|
||||||
|
|
||||||
getOptions((opts) => {
|
bgGetOptions((opts) => {
|
||||||
this.setOptions(opts);
|
this.setOptions(opts);
|
||||||
getState((state) => this.setEnabled(state === 'enabled'));
|
bgGetState((state) => this.setEnabled(state === 'enabled'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,19 +101,21 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
range.setLength(this.options.scanLength);
|
range.setLength(this.options.scanLength);
|
||||||
findTerm(range.text(), ({definitions, length}) => {
|
bgFindTerm(range.text(), ({definitions, length}) => {
|
||||||
if (length === 0) {
|
if (length === 0) {
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
} else {
|
} else {
|
||||||
range.setLength(length);
|
range.setLength(length);
|
||||||
renderText(
|
bgRenderText(
|
||||||
{defs: definitions, root: this.fgRoot, options: this.options},
|
{defs: definitions, root: this.fgRoot, options: this.options},
|
||||||
'term-list.html',
|
'term-list.html',
|
||||||
(content) => {
|
(content) => {
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
this.showPopup(range, content);
|
this.showPopup(range, content);
|
||||||
canAddNotes(definitions, (states) => {
|
bgCanAddNotes(definitions, (states) => {
|
||||||
|
if (states !== null) {
|
||||||
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index: index, state: state}));
|
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index: index, state: state}));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -129,8 +131,8 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actionDisplayKanji(kanji) {
|
actionDisplayKanji(kanji) {
|
||||||
findKanji(kanji, (definitions) => {
|
bgFindKanji(kanji, (definitions) => {
|
||||||
renderText(
|
bgRenderText(
|
||||||
{defs: definitions, root: this.fgRoot, options: this.options},
|
{defs: definitions, root: this.fgRoot, options: this.options},
|
||||||
'kanji-list.html',
|
'kanji-list.html',
|
||||||
(content) => {
|
(content) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user