aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/float.js9
-rw-r--r--ext/fg/js/frontend-initialize.js20
-rw-r--r--ext/fg/js/frontend.js15
-rw-r--r--ext/fg/js/popup-nested.js3
-rw-r--r--ext/fg/js/popup.js4
5 files changed, 43 insertions, 8 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 8fdb6925..533d98e1 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -96,7 +96,7 @@ class DisplayFloat extends Display {
}
}
- initialize(options, popupInfo, url) {
+ initialize(options, popupInfo, url, childrenSupported) {
const css = options.general.customPopupCss;
if (css) {
this.setStyle(css);
@@ -105,7 +105,10 @@ class DisplayFloat extends Display {
const {id, depth, parentFrameId} = popupInfo;
this.optionsContext.depth = depth;
this.optionsContext.url = url;
- popupNestedInitialize(id, depth, parentFrameId, url);
+
+ if (childrenSupported) {
+ popupNestedInitialize(id, depth, parentFrameId, url);
+ }
}
setStyle(css) {
@@ -138,7 +141,7 @@ DisplayFloat.messageHandlers = {
kanjiShow: (self, {definitions, options, context}) => self.kanjiShow(definitions, options, context),
clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),
orphaned: (self) => self.onOrphaned(),
- initialize: (self, {options, popupInfo, url}) => self.initialize(options, popupInfo, url)
+ initialize: (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported)
};
window.yomichan_display = new DisplayFloat();
diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js
new file mode 100644
index 00000000..37a82faa
--- /dev/null
+++ b/ext/fg/js/frontend-initialize.js
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2019 Alex Yatskov <alex@foosoft.net>
+ * Author: Alex Yatskov <alex@foosoft.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+window.yomichan_frontend = Frontend.create();
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();
diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js
index b36de2ec..f7309466 100644
--- a/ext/fg/js/popup-nested.js
+++ b/ext/fg/js/popup-nested.js
@@ -41,7 +41,8 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) {
'/fg/js/frontend-api-sender.js',
'/fg/js/popup.js',
'/fg/js/popup-proxy.js',
- '/fg/js/frontend.js'
+ '/fg/js/frontend.js',
+ '/fg/js/frontend-initialize.js'
];
for (const src of scriptSrcs) {
const script = document.createElement('script');
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 9ca91afa..7f96fe97 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -25,6 +25,7 @@ class Popup {
this.frameId = null;
this.parent = null;
this.child = null;
+ this.childrenSupported = true;
this.container = document.createElement('iframe');
this.container.id = 'yomichan-float';
this.container.addEventListener('mousedown', e => e.stopPropagation());
@@ -70,7 +71,8 @@ class Popup {
depth: this.depth,
parentFrameId
},
- url: this.url
+ url: this.url,
+ childrenSupported: this.childrenSupported
});
resolve();
});