Cleanup
This commit is contained in:
parent
f65e9f2570
commit
997947caed
@ -156,6 +156,10 @@ class Yomichan {
|
|||||||
this.ankiInvoke('modelNames', {}, null, callback);
|
this.ankiInvoke('modelNames', {}, null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api_getModelFieldNames({callback}) {
|
||||||
|
this.ankiInvoke('modelFieldNames', {}, null, callback);
|
||||||
|
}
|
||||||
|
|
||||||
api_getOptions({callback}) {
|
api_getOptions({callback}) {
|
||||||
callback(this.options);
|
callback(this.options);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@
|
|||||||
<th>Value</th>
|
<th>Value</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="ankiVocabFields">
|
<tbody class="ankiFields">
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@ -126,7 +126,7 @@
|
|||||||
<th>Value</th>
|
<th>Value</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="ankiKanjiFields">
|
<tbody class="ankiFields">
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -17,10 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Background APIs
|
|
||||||
//
|
|
||||||
|
|
||||||
function bgSendMessage(action, params, callback) {
|
function bgSendMessage(action, params, callback) {
|
||||||
chrome.runtime.sendMessage({action, params}, callback);
|
chrome.runtime.sendMessage({action, params}, callback);
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ class Client {
|
|||||||
} else {
|
} else {
|
||||||
const sequence = ++this.sequence;
|
const sequence = ++this.sequence;
|
||||||
range.setLength(length);
|
range.setLength(length);
|
||||||
|
|
||||||
bgRenderText(
|
bgRenderText(
|
||||||
{defs: definitions, root: this.fgRoot, options: this.options, sequence: sequence},
|
{defs: definitions, root: this.fgRoot, options: this.options, sequence: sequence},
|
||||||
'term-list.html',
|
'term-list.html',
|
||||||
|
@ -42,26 +42,25 @@ function onDomContentLoaded() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onMessage(e) {
|
function onMessage(e) {
|
||||||
const {action, params} = e.data, handlers = {
|
const {action, params} = e.data, method = window['api_' + action];
|
||||||
setActionState: ({index, state, sequence}) => {
|
if (typeof(method) === 'function') {
|
||||||
for (const mode in state) {
|
method(params);
|
||||||
const matches = document.querySelectorAll(`.action-link[data-sequence="${sequence}"][data-index="${index}"][data-mode="${mode}"]`);
|
}
|
||||||
if (matches.length === 0) {
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const classes = matches[0].classList;
|
function api_setActionState({index, state, sequence}) {
|
||||||
if (state[mode]) {
|
for (const mode in state) {
|
||||||
classes.remove('disabled');
|
const matches = document.querySelectorAll(`.action-link[data-sequence="${sequence}"][data-index="${index}"][data-mode="${mode}"]`);
|
||||||
} else {
|
if (matches.length === 0) {
|
||||||
classes.add('disabled');
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
if (handlers.hasOwnProperty(action)) {
|
const classes = matches[0].classList;
|
||||||
handlers[action](params);
|
if (state[mode]) {
|
||||||
|
classes.remove('disabled');
|
||||||
|
} else {
|
||||||
|
classes.add('disabled');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user