Move event handler function bodies

This commit is contained in:
toasted-nutbread 2020-02-26 19:04:21 -05:00
parent 81fbe60da9
commit 0c1b250b4f

View File

@ -69,18 +69,7 @@ class DisplaySearch extends Display {
} else { } else {
this.wanakanaEnable.checked = false; this.wanakanaEnable.checked = false;
} }
this.wanakanaEnable.addEventListener('change', (e) => { this.wanakanaEnable.addEventListener('change', (e) => this.onWanakanaEnableChange(e));
const {queryParams: {query: query2=''}} = parseUrl(window.location.href);
if (e.target.checked) {
window.wanakana.bind(this.query);
apiOptionsSet({general: {enableWanakana: true}}, this.getOptionsContext());
} else {
window.wanakana.unbind(this.query);
apiOptionsSet({general: {enableWanakana: false}}, this.getOptionsContext());
}
this.setQuery(query2);
this.onSearchQueryUpdated(this.query.value, false);
});
} }
this.setQuery(query); this.setQuery(query);
@ -93,24 +82,7 @@ class DisplaySearch extends Display {
} else { } else {
this.clipboardMonitorEnable.checked = false; this.clipboardMonitorEnable.checked = false;
} }
this.clipboardMonitorEnable.addEventListener('change', (e) => { this.clipboardMonitorEnable.addEventListener('change', (e) => this.onClipboardMonitorEnableChange(e));
if (e.target.checked) {
chrome.permissions.request(
{permissions: ['clipboardRead']},
(granted) => {
if (granted) {
this.clipboardMonitor.start();
apiOptionsSet({general: {enableClipboardMonitor: true}}, this.getOptionsContext());
} else {
e.target.checked = false;
}
}
);
} else {
this.clipboardMonitor.stop();
apiOptionsSet({general: {enableClipboardMonitor: false}}, this.getOptionsContext());
}
});
} }
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this)); chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
@ -253,6 +225,38 @@ class DisplaySearch extends Display {
} }
} }
onWanakanaEnableChange(e) {
const {queryParams: {query=''}} = parseUrl(window.location.href);
const enableWanakana = e.target.checked;
if (enableWanakana) {
window.wanakana.bind(this.query);
} else {
window.wanakana.unbind(this.query);
}
this.setQuery(query);
this.onSearchQueryUpdated(this.query.value, false);
apiOptionsSet({general: {enableWanakana}}, this.getOptionsContext());
}
onClipboardMonitorEnableChange(e) {
if (e.target.checked) {
chrome.permissions.request(
{permissions: ['clipboardRead']},
(granted) => {
if (granted) {
this.clipboardMonitor.start();
apiOptionsSet({general: {enableClipboardMonitor: true}}, this.getOptionsContext());
} else {
e.target.checked = false;
}
}
);
} else {
this.clipboardMonitor.stop();
apiOptionsSet({general: {enableClipboardMonitor: false}}, this.getOptionsContext());
}
}
async updateOptions(options) { async updateOptions(options) {
await super.updateOptions(options); await super.updateOptions(options);
this.queryParser.setOptions(this.options); this.queryParser.setOptions(this.options);