simplify element source lazy load
This commit is contained in:
parent
691b739849
commit
a81c33b60a
@ -94,27 +94,9 @@ class FrameOffsetForwarder {
|
||||
}
|
||||
|
||||
_findFrameWithContentWindow(contentWindow) {
|
||||
const elementSources = [
|
||||
() => [...this._frameCache],
|
||||
// will contain duplicates, but frame elements are cheap to handle
|
||||
() => [...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 || elements.push(...getMoreElements())) {
|
||||
for (const elements of this._getFrameElementSources()) {
|
||||
while (elements.length > 0) {
|
||||
const element = elements.shift();
|
||||
if (element.contentWindow === contentWindow) {
|
||||
this._frameCache.add(element);
|
||||
@ -136,10 +118,18 @@ class FrameOffsetForwarder {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
*_getFrameElementSources() {
|
||||
yield [...this._frameCache];
|
||||
// will contain duplicates, but frame elements are cheap to handle
|
||||
yield [...document.querySelectorAll('frame, iframe:not(.yomichan-float)')];
|
||||
yield [document.documentElement];
|
||||
}
|
||||
|
||||
_forwardFrameOffsetParent(offset, uniqueId) {
|
||||
window.parent.postMessage({action: 'getFrameOffset', params: {offset, uniqueId}}, '*');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user