Cleanup
This commit is contained in:
parent
b87611cfdd
commit
b969e8952c
@ -54,10 +54,10 @@ class Translator {
|
|||||||
percent += banks[url].loaded / banks[url].total;
|
percent += banks[url].loaded / banks[url].total;
|
||||||
}
|
}
|
||||||
|
|
||||||
percent /= 3;
|
percent /= 3.0;
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({state: 'update', progress: Math.ceil(100 * percent)});
|
callback({state: 'update', progress: Math.ceil(100.0 * percent)});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class Translator {
|
|||||||
return this.dictionary.sealDb();
|
return this.dictionary.sealDb();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({state: 'end', progress: 100});
|
callback({state: 'end', progress: 100.0});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
@ -116,7 +116,7 @@ class Client {
|
|||||||
return canAddDefinitions(definitions, ['term_kanji', 'term_kana']);
|
return canAddDefinitions(definitions, ['term_kanji', 'term_kana']);
|
||||||
}).then(states => {
|
}).then(states => {
|
||||||
if (states !== null) {
|
if (states !== null) {
|
||||||
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index, state, sequence }));
|
states.forEach((state, index) => this.popup.invokeApi('setActionState', {index, state, sequence}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ class Client {
|
|||||||
const state = {[mode]: false};
|
const state = {[mode]: false};
|
||||||
addDefinition(this.definitions[index], mode).then(success => {
|
addDefinition(this.definitions[index], mode).then(success => {
|
||||||
if (success) {
|
if (success) {
|
||||||
this.popup.sendMessage('setActionState', {index, state, sequence: this.sequence});
|
this.popup.invokeApi('setActionState', {index, state, sequence: this.sequence});
|
||||||
} else {
|
} else {
|
||||||
alert('Note could not be added');
|
alert('Note could not be added');
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ class Client {
|
|||||||
return canAddDefinitions(definitions, ['kanji']);
|
return canAddDefinitions(definitions, ['kanji']);
|
||||||
}).then(states => {
|
}).then(states => {
|
||||||
if (states !== null) {
|
if (states !== null) {
|
||||||
states.forEach((state, index) => this.popup.sendMessage('setActionState', {index, state, sequence}));
|
states.forEach((state, index) => this.popup.invokeApi('setActionState', {index, state, sequence}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -17,11 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function invokeApi(action, params, target) {
|
||||||
|
target.postMessage({action, params}, '*');
|
||||||
|
}
|
||||||
|
|
||||||
function registerKanjiLinks() {
|
function registerKanjiLinks() {
|
||||||
for (const link of Array.from(document.getElementsByClassName('kanji-link'))) {
|
for (const link of Array.from(document.getElementsByClassName('kanji-link'))) {
|
||||||
link.addEventListener('click', e => {
|
link.addEventListener('click', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
window.parent.postMessage({action: 'displayKanji', params: e.target.innerHTML}, '*');
|
invokeApi('displayKanji', e.target.innerHTML, window.parent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +35,7 @@ function registerAddNoteLinks() {
|
|||||||
link.addEventListener('click', e => {
|
link.addEventListener('click', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const ds = e.currentTarget.dataset;
|
const ds = e.currentTarget.dataset;
|
||||||
window.parent.postMessage({action: 'addNote', params: {index: ds.index, mode: ds.mode}}, '*');
|
invokeApi('addNote', {index: ds.index, mode: ds.mode}, window.parent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,7 +45,7 @@ function registerAudioLinks() {
|
|||||||
link.addEventListener('click', e => {
|
link.addEventListener('click', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const ds = e.currentTarget.dataset;
|
const ds = e.currentTarget.dataset;
|
||||||
window.parent.postMessage({action: 'playAudio', params: ds.index}, '*');
|
invokeApi('playAudio', ds.index, window.parent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class Popup {
|
|||||||
doc.close();
|
doc.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(action, params, callback) {
|
invokeApi(action, params) {
|
||||||
if (this.popup !== null) {
|
if (this.popup !== null) {
|
||||||
this.popup.contentWindow.postMessage({action, params}, '*');
|
this.popup.contentWindow.postMessage({action, params}, '*');
|
||||||
}
|
}
|
||||||
|
@ -17,28 +17,28 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function sendMessage(action, params) {
|
function invokeApiBg(action, params) {
|
||||||
return new Promise((resolve, reject) => chrome.runtime.sendMessage({action, params}, resolve));
|
return new Promise((resolve, reject) => chrome.runtime.sendMessage({action, params}, resolve));
|
||||||
}
|
}
|
||||||
|
|
||||||
function findTerm(text) {
|
function findTerm(text) {
|
||||||
return sendMessage('findTerm', {text});
|
return invokeApiBg('findTerm', {text});
|
||||||
}
|
}
|
||||||
|
|
||||||
function findKanji(text) {
|
function findKanji(text) {
|
||||||
return sendMessage('findKanji', {text});
|
return invokeApiBg('findKanji', {text});
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderText(data, template) {
|
function renderText(data, template) {
|
||||||
return sendMessage('renderText', {data, template});
|
return invokeApiBg('renderText', {data, template});
|
||||||
}
|
}
|
||||||
|
|
||||||
function canAddDefinitions(definitions, modes) {
|
function canAddDefinitions(definitions, modes) {
|
||||||
return sendMessage('canAddDefinitions', {definitions, modes});
|
return invokeApiBg('canAddDefinitions', {definitions, modes});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDefinition(definition, mode) {
|
function addDefinition(definition, mode) {
|
||||||
return sendMessage('addDefinition', {definition, mode});
|
return invokeApiBg('addDefinition', {definition, mode});
|
||||||
}
|
}
|
||||||
|
|
||||||
function textSourceFromPoint(point) {
|
function textSourceFromPoint(point) {
|
||||||
|
Loading…
Reference in New Issue
Block a user