run script in iframe

This commit is contained in:
Gabe Yuan
2023-08-24 16:39:35 +08:00
parent 2665f31d94
commit 4633bf4fc6
2 changed files with 8 additions and 15 deletions

View File

@@ -138,7 +138,7 @@ export class Translator {
_queryNodes = (rootNode = document) => {
const childRoots = Array.from(rootNode.querySelectorAll("*"))
.map((item) => item.shadowRoot || item.contentDocument)
.map((item) => item.shadowRoot)
.filter(Boolean);
const childNodes = childRoots.map((item) => this._queryNodes(item));
const nodes = Array.from(rootNode.querySelectorAll(this.rule.selector));
@@ -147,18 +147,11 @@ export class Translator {
_register = () => {
// 监听节点变化;
[
document,
...Array.from(document.querySelectorAll("iframe")).map(
(iframe) => iframe.contentWindow.document
),
].forEach((item) => {
this._mutaObserver.observe(item, {
this._mutaObserver.observe(document, {
childList: true,
subtree: true,
// characterData: true,
});
});
// 监听节点显示
this._queryNodes().forEach((el) => {

View File

@@ -24,9 +24,9 @@ import { isGm } from "./libs/browser";
}
// skip iframe
if (window.self !== window.top) {
return;
}
// if (window.self !== window.top) {
// return;
// }
// 翻译页面
const setting = await getSetting();