aboutsummaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-18 00:55:16 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-18 23:28:00 +0300
commitb786e2da1912dfa7d707db628d54fb914189f7d1 (patch)
tree838a4b3fe95ff058db9f5d03cb9ecd6035a30932 /ext/fg
parent85706c421b7496d2d73a0f3d1f7721d39d5d0b3f (diff)
move open shadow root iframe finder to a function
Diffstat (limited to 'ext/fg')
-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}}, '*');
}