content script in iframe

This commit is contained in:
Gabe Yuan
2023-08-26 12:02:16 +08:00
parent 3bf0cb2485
commit c5fa6689a4
3 changed files with 7 additions and 3 deletions

View File

@@ -12,7 +12,8 @@
"content_scripts": [
{
"js": ["content.js"],
"matches": ["<all_urls>"]
"matches": ["<all_urls>"],
"all_frames": true
}
],
"commands": {

View File

@@ -13,7 +13,8 @@
"content_scripts": [
{
"js": ["content.js"],
"matches": ["<all_urls>"]
"matches": ["<all_urls>"],
"all_frames": true
}
],
"commands": {

View File

@@ -7,14 +7,16 @@ import {
} from "./config";
import { getSetting, getRules, matchRule } from "./libs";
import { Translator } from "./libs/translator";
import { isIframe } from "./libs/iframe";
/**
* 入口函数
*/
(async () => {
const href = isIframe ? document.referrer : document.location.href;
const setting = await getSetting();
const rules = await getRules();
const rule = await matchRule(rules, document.location.href, setting);
const rule = await matchRule(rules, href, setting);
const translator = new Translator(rule, setting);
// 监听消息