run script in iframe
This commit is contained in:
@@ -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) => {
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user