diff options
Diffstat (limited to 'ext/fg/js/frontend.js')
-rw-r--r-- | ext/fg/js/frontend.js | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 67045241..768b9326 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -16,7 +16,14 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -/*global apiGetZoom, apiOptionsGet, apiTermsFind, apiKanjiFind, docSentenceExtract, TextScanner*/ +/* global + * TextScanner + * apiGetZoom + * apiKanjiFind + * apiOptionsGet + * apiTermsFind + * docSentenceExtract + */ class Frontend extends TextScanner { constructor(popup, ignoreNodes) { @@ -39,6 +46,15 @@ class Frontend extends TextScanner { this._contentScale = 1.0; this._orphaned = true; this._lastShowPromise = Promise.resolve(); + + this._windowMessageHandlers = new Map([ + ['popupClose', () => this.onSearchClear(true)], + ['selectionCopy', () => document.execCommand('copy')] + ]); + + this._runtimeMessageHandlers = new Map([ + ['popupSetVisibleOverride', ({visible}) => { this.popup.setVisibleOverride(visible); }] + ]); } async prepare() { @@ -55,9 +71,9 @@ class Frontend extends TextScanner { window.visualViewport.addEventListener('resize', this.onVisualViewportResize.bind(this)); } - yomichan.on('orphaned', () => this.onOrphaned()); - yomichan.on('optionsUpdated', () => this.updateOptions()); - yomichan.on('zoomChanged', (e) => this.onZoomChanged(e)); + yomichan.on('orphaned', this.onOrphaned.bind(this)); + yomichan.on('optionsUpdated', this.updateOptions.bind(this)); + yomichan.on('zoomChanged', this.onZoomChanged.bind(this)); chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this)); this._updateContentScale(); @@ -72,17 +88,17 @@ class Frontend extends TextScanner { onWindowMessage(e) { const action = e.data; - const handler = Frontend._windowMessageHandlers.get(action); + const handler = this._windowMessageHandlers.get(action); if (typeof handler !== 'function') { return false; } - handler(this); + handler(); } onRuntimeMessage({action, params}, sender, callback) { - const handler = Frontend._runtimeMessageHandlers.get(action); + const handler = this._runtimeMessageHandlers.get(action); if (typeof handler !== 'function') { return false; } - const result = handler(this, params, sender); + const result = handler(params, sender); callback(result); return false; } @@ -237,12 +253,3 @@ class Frontend extends TextScanner { return visualViewport !== null && typeof visualViewport === 'object' ? visualViewport.scale : 1.0; } } - -Frontend._windowMessageHandlers = new Map([ - ['popupClose', (self) => self.onSearchClear(true)], - ['selectionCopy', () => document.execCommand('copy')] -]); - -Frontend._runtimeMessageHandlers = new Map([ - ['popupSetVisibleOverride', (self, {visible}) => { self.popup.setVisibleOverride(visible); }] -]); |