From 5c4614f585648c2b835efc1d369e78918bc4f5ff Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 17 Aug 2019 18:50:48 -0400 Subject: Add support for showing recursive popups --- ext/fg/js/frontend.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'ext/fg/js/frontend.js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 8a5c48d0..d378dd61 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -18,8 +18,8 @@ class Frontend { - constructor() { - this.popup = new Popup(); + constructor(popup) { + this.popup = popup; this.popupTimer = null; this.mouseDownLeft = false; this.mouseDownMiddle = false; @@ -36,6 +36,25 @@ class Frontend { this.scrollPrevent = false; } + static create() { + const floatUrl = chrome.extension.getURL('/fg/float.html'); + const currentUrl = location.href.replace(/[\?#][\w\W]*$/, ""); + const isNested = (currentUrl === floatUrl); + + let id = null; + if (isNested) { + const match = /[&?]id=([^&]*?)(?:&|$)/.exec(location.href); + if (match !== null) { + id = match[1]; + } + } + + const popup = isNested ? new PopupProxy(id) : PopupProxyHost.instance.createPopup(); + const frontend = new Frontend(popup); + frontend.prepare(); + return frontend; + } + async prepare() { try { this.options = await apiOptionsGet(); @@ -259,9 +278,8 @@ class Frontend { const handler = handlers[action]; if (handler) { handler(params); + callback(); } - - callback(); } onError(error) { @@ -281,7 +299,10 @@ class Frontend { } async searchAt(point, type) { - if (this.pendingLookup || this.popup.containsPoint(point)) { + if ( + this.pendingLookup || + (this.popup.containsPointIsAsync() ? await this.popup.containsPointAsync(point) : this.popup.containsPoint(point)) + ) { return; } @@ -482,5 +503,4 @@ class Frontend { } } -window.yomichan_frontend = new Frontend(); -window.yomichan_frontend.prepare(); +window.yomichan_frontend = Frontend.create(); -- cgit v1.2.3