aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/frame-offset-forwarder.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js/frame-offset-forwarder.js')
-rw-r--r--ext/fg/js/frame-offset-forwarder.js36
1 files changed, 20 insertions, 16 deletions
diff --git a/ext/fg/js/frame-offset-forwarder.js b/ext/fg/js/frame-offset-forwarder.js
index ac6e617d..2b48ba26 100644
--- a/ext/fg/js/frame-offset-forwarder.js
+++ b/ext/fg/js/frame-offset-forwarder.js
@@ -81,23 +81,9 @@ class FrameOffsetForwarder {
}
if (sourceFrame === null) {
- const getShadowRootElements = (documentOrElement) => {
- const elements = Array.from(documentOrElement.querySelectorAll('*'))
- .filter((el) => !!el.shadowRoot);
- const childElements = elements
- .map((el) => el.shadowRoot)
- .map(getShadowRootElements);
- elements.push(childElements.flat());
-
- return elements.flat();
- };
-
- sourceFrame = getShadowRootElements(document)
- .map((el) => Array.from(el.shadowRoot.querySelectorAll('frame, iframe:not(.yomichan-float)')))
- .flat()
- .find((el) => el.contentWindow === e.source);
-
+ sourceFrame = this._getOpenShadowRootSourceFrame(e.source);
if (!sourceFrame) {
+ // closed shadow root etc.
this._forwardFrameOffsetOrigin(null, uniqueId);
return;
}
@@ -110,6 +96,24 @@ class FrameOffsetForwarder {
this._forwardFrameOffset(offset, uniqueId);
}
+ _getOpenShadowRootSourceFrame(sourceWindow) {
+ const getShadowRootElements = (documentOrElement) => {
+ const elements = Array.from(documentOrElement.querySelectorAll('*'))
+ .filter((el) => !!el.shadowRoot);
+ const childElements = elements
+ .map((el) => el.shadowRoot)
+ .map(getShadowRootElements);
+ elements.push(childElements.flat());
+
+ return elements.flat();
+ };
+
+ return getShadowRootElements(document)
+ .map((el) => Array.from(el.shadowRoot.querySelectorAll('frame, iframe:not(.yomichan-float)')))
+ .flat()
+ .find((el) => el.contentWindow === sourceWindow);
+ }
+
_forwardFrameOffsetParent(offset, uniqueId) {
window.parent.postMessage({action: 'getFrameOffset', params: {offset, uniqueId}}, '*');
}