summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-18 17:18:33 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-18 23:28:00 +0300
commit66354f1f9e866fd31f6bb0365024a39697a54079 (patch)
treeca7141db235ec0b5757ca50b5dd0ba84d207dbc3
parentbb3ad78e373b01b64a24fc46712f24964528a24f (diff)
lazy load element sources
-rw-r--r--ext/fg/js/frame-offset-forwarder.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/ext/fg/js/frame-offset-forwarder.js b/ext/fg/js/frame-offset-forwarder.js
index c2df7581..4b77d5ed 100644
--- a/ext/fg/js/frame-offset-forwarder.js
+++ b/ext/fg/js/frame-offset-forwarder.js
@@ -89,14 +89,27 @@ class FrameOffsetForwarder {
}
_findFrameWithContentWindow(contentWindow) {
- const elements = [
- ...this._frameCache,
+ const elementSources = [
+ () => [...this._frameCache],
// will contain duplicates, but frame elements are cheap to handle
- ...document.querySelectorAll('frame, iframe:not(.yomichan-float)'),
- document.documentElement
+ () => [...document.querySelectorAll('frame, iframe:not(.yomichan-float)')],
+ () => [document.documentElement]
];
+ const getMoreElements = () => {
+ while (true) {
+ const source = elementSources.shift();
+ if (source) {
+ const elements = source();
+ if (elements.length === 0) { continue; }
+ return elements;
+ }
+ return [];
+ }
+ };
+
+ const elements = [];
const ELEMENT_NODE = Node.ELEMENT_NODE;
- while (elements.length > 0) {
+ while (elements.length > 0 || elements.push(...getMoreElements())) {
const element = elements.shift();
if (element.contentWindow === contentWindow) {
this._frameCache.add(element);