polish and initial command support
This commit is contained in:
parent
e782a43432
commit
57697ee2a0
@ -20,8 +20,13 @@
|
|||||||
window.displayWindow = new class extends Display {
|
window.displayWindow = new class extends Display {
|
||||||
constructor() {
|
constructor() {
|
||||||
super($('#spinner'), $('#content'));
|
super($('#spinner'), $('#content'));
|
||||||
$('#search').click(this.onSearch.bind(this));
|
|
||||||
window.wanakana.bind($('#query').get(0));
|
const search = $('#search');
|
||||||
|
search.click(this.onSearch.bind(this));
|
||||||
|
|
||||||
|
const query = $('#query');
|
||||||
|
query.on('input', () => search.prop('disabled', query.val().length === 0));
|
||||||
|
window.wanakana.bind(query.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
definitionAdd(definition, mode) {
|
definitionAdd(definition, mode) {
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
$('#open-search').click(() => window.open(chrome.extension.getURL('/bg/search.html')));
|
$('#open-search').click(() => commandExec('search'));
|
||||||
$('#open-options').click(() => chrome.runtime.openOptionsPage());
|
$('#open-options').click(() => chrome.runtime.openOptionsPage());
|
||||||
$('#open-help').click(() => window.open('http://foosoft.net/projects/yomichan'));
|
$('#open-help').click(() => window.open('http://foosoft.net/projects/yomichan'));
|
||||||
|
|
||||||
@ -26,9 +26,6 @@ $(document).ready(() => {
|
|||||||
const toggle = $('#enable-search');
|
const toggle = $('#enable-search');
|
||||||
toggle.prop('checked', options.general.enable).change();
|
toggle.prop('checked', options.general.enable).change();
|
||||||
toggle.bootstrapToggle();
|
toggle.bootstrapToggle();
|
||||||
toggle.change(() => {
|
toggle.change(() => commandExec('toggle'));
|
||||||
options.general.enable = toggle.prop('checked');
|
|
||||||
optionsSave(options).then(() => instYomi().optionsSet(options));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -33,6 +33,15 @@ function promiseCallback(promise, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Commands
|
||||||
|
*/
|
||||||
|
|
||||||
|
function commandExec(command) {
|
||||||
|
instYomi().onCommand(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Instance
|
* Instance
|
||||||
*/
|
*/
|
||||||
|
@ -25,12 +25,13 @@ window.yomichan = new class {
|
|||||||
this.anki = new AnkiNull();
|
this.anki = new AnkiNull();
|
||||||
this.options = null;
|
this.options = null;
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this)).then(() => {
|
||||||
if (chrome.runtime.onInstalled) {
|
chrome.commands.onCommand.addListener(this.onCommand.bind(this));
|
||||||
chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this));
|
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
||||||
}
|
if (chrome.runtime.onInstalled) {
|
||||||
|
chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this));
|
||||||
this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this));
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
optionsSet(options) {
|
optionsSet(options) {
|
||||||
@ -153,6 +154,15 @@ window.yomichan = new class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCommand(command) {
|
||||||
|
if (command === 'search') {
|
||||||
|
window.open(chrome.extension.getURL('/bg/search.html'));
|
||||||
|
} else if (command === 'toggle') {
|
||||||
|
this.options.general.enable = !this.options.general.enable;
|
||||||
|
optionsSave(this.options).then(() => this.optionsSet(this.options));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMessage(request, sender, callback) {
|
onMessage(request, sender, callback) {
|
||||||
const handlers = new class {
|
const handlers = new class {
|
||||||
api_optionsGet({callback}) {
|
api_optionsGet({callback}) {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<form class="input-group">
|
<form class="input-group">
|
||||||
<input type="text" class="form-control" placeholder="Search for..." id="query" autofocus>
|
<input type="text" class="form-control" placeholder="Search for..." id="query" autofocus>
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<input type="submit" class="btn btn-default form-control" id="search" value="Search">
|
<input type="submit" class="btn btn-default form-control" id="search" value="Search" disabled>
|
||||||
</span>
|
</span>
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
|
@ -31,6 +31,20 @@
|
|||||||
"<all_urls>",
|
"<all_urls>",
|
||||||
"storage"
|
"storage"
|
||||||
],
|
],
|
||||||
|
"commands": {
|
||||||
|
"toggle": {
|
||||||
|
"suggested_key": {
|
||||||
|
"default": "Alt+Delete"
|
||||||
|
},
|
||||||
|
"description": "Toggle text scanning"
|
||||||
|
},
|
||||||
|
"search": {
|
||||||
|
"suggested_key": {
|
||||||
|
"default": "Alt+Insert"
|
||||||
|
},
|
||||||
|
"description": "Open search window"
|
||||||
|
}
|
||||||
|
},
|
||||||
"web_accessible_resources": ["fg/frame.html"],
|
"web_accessible_resources": ["fg/frame.html"],
|
||||||
"applications": {
|
"applications": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
|
Loading…
Reference in New Issue
Block a user