Use static object for api command handlers
This commit is contained in:
parent
10458c63e7
commit
0d6177398d
@ -126,35 +126,35 @@ async function apiTemplateRender(template, data, dynamic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function apiCommandExec(command) {
|
async function apiCommandExec(command) {
|
||||||
const handlers = {
|
const handlers = apiCommandExec.handlers;
|
||||||
search: () => {
|
if (handlers.hasOwnProperty(command)) {
|
||||||
chrome.tabs.create({url: chrome.extension.getURL('/bg/search.html')});
|
const handler = handlers[command];
|
||||||
},
|
|
||||||
|
|
||||||
help: () => {
|
|
||||||
chrome.tabs.create({url: 'https://foosoft.net/projects/yomichan/'});
|
|
||||||
},
|
|
||||||
|
|
||||||
options: () => {
|
|
||||||
chrome.runtime.openOptionsPage();
|
|
||||||
},
|
|
||||||
|
|
||||||
toggle: async () => {
|
|
||||||
const optionsContext = {
|
|
||||||
depth: 0,
|
|
||||||
url: window.location.href
|
|
||||||
};
|
|
||||||
const options = await apiOptionsGet(optionsContext);
|
|
||||||
options.general.enable = !options.general.enable;
|
|
||||||
await apiOptionsSave('popup');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handler = handlers[command];
|
|
||||||
if (handler) {
|
|
||||||
handler();
|
handler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
apiCommandExec.handlers = {
|
||||||
|
search: () => {
|
||||||
|
chrome.tabs.create({url: chrome.extension.getURL('/bg/search.html')});
|
||||||
|
},
|
||||||
|
|
||||||
|
help: () => {
|
||||||
|
chrome.tabs.create({url: 'https://foosoft.net/projects/yomichan/'});
|
||||||
|
},
|
||||||
|
|
||||||
|
options: () => {
|
||||||
|
chrome.runtime.openOptionsPage();
|
||||||
|
},
|
||||||
|
|
||||||
|
toggle: async () => {
|
||||||
|
const optionsContext = {
|
||||||
|
depth: 0,
|
||||||
|
url: window.location.href
|
||||||
|
};
|
||||||
|
const options = await apiOptionsGet(optionsContext);
|
||||||
|
options.general.enable = !options.general.enable;
|
||||||
|
await apiOptionsSave('popup');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async function apiAudioGetUrl(definition, source) {
|
async function apiAudioGetUrl(definition, source) {
|
||||||
return audioBuildUrl(definition, source);
|
return audioBuildUrl(definition, source);
|
||||||
|
Loading…
Reference in New Issue
Block a user