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

View File

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