From cc72514ce6260bc489b8dd9b51ea27b9fb6e3ce8 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 11 Oct 2019 22:35:59 -0400 Subject: Frontend updates --- ext/fg/js/frontend.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'ext/fg/js/frontend.js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 88cb93a9..1c41cad1 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -41,6 +41,9 @@ class Frontend { this.enabled = false; this.eventListeners = []; + + this.isPreparedPromiseResolve = null; + this.isPreparedPromise = new Promise((resolve) => { this.isPreparedPromiseResolve = resolve; }); } static create() { @@ -59,11 +62,16 @@ class Frontend { await this.updateOptions(); chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this)); + this.isPreparedPromiseResolve(); } catch (e) { this.onError(e); } } + isPrepared() { + return this.isPreparedPromise; + } + onMouseOver(e) { if (e.target === this.popup.container && this.popupTimer !== null) { this.popupTimerClear(); @@ -303,6 +311,10 @@ class Frontend { } const textSource = docRangeFromPoint(x, y, this.options); + return await this.searchSource(textSource, cause); + } + + async searchSource(textSource, cause) { let hideResults = textSource === null; let searched = false; let success = false; @@ -560,6 +572,3 @@ Frontend.runtimeMessageHandlers = { self.popup.setVisibleOverride(visible); } }; - - -window.yomichan_frontend = Frontend.create(); -- cgit v1.2.3