From 0c1b250b4f72a0de6348b119a050d19c6e767113 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 26 Feb 2020 19:04:21 -0500 Subject: Move event handler function bodies --- ext/bg/js/search.js | 64 ++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 98e167ad..59cb8636 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -69,18 +69,7 @@ class DisplaySearch extends Display { } else { this.wanakanaEnable.checked = false; } - this.wanakanaEnable.addEventListener('change', (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.wanakanaEnable.addEventListener('change', (e) => this.onWanakanaEnableChange(e)); } this.setQuery(query); @@ -93,24 +82,7 @@ class DisplaySearch extends Display { } else { this.clipboardMonitorEnable.checked = false; } - this.clipboardMonitorEnable.addEventListener('change', (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()); - } - }); + this.clipboardMonitorEnable.addEventListener('change', (e) => this.onClipboardMonitorEnableChange(e)); } 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) { await super.updateOptions(options); this.queryParser.setOptions(this.options); -- cgit v1.2.3