modify entry func
This commit is contained in:
@@ -6,19 +6,16 @@ import {
|
|||||||
} from "./config";
|
} from "./config";
|
||||||
import { getRules, matchRule } from "./libs";
|
import { getRules, matchRule } from "./libs";
|
||||||
import { getSetting } from "./libs";
|
import { getSetting } from "./libs";
|
||||||
import { fetchUpdate } from "./libs/fetch";
|
|
||||||
import { Translator } from "./libs/translator";
|
import { Translator } from "./libs/translator";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 入口函数
|
* 入口函数
|
||||||
*/
|
*/
|
||||||
(async () => {
|
(async () => {
|
||||||
const { fetchInterval, fetchLimit } = await getSetting();
|
const setting = await getSetting();
|
||||||
fetchUpdate(fetchInterval, fetchLimit);
|
|
||||||
|
|
||||||
const rules = await getRules();
|
const rules = await getRules();
|
||||||
const rule = matchRule(rules, document.location.href);
|
const rule = matchRule(rules, document.location.href);
|
||||||
const translator = new Translator(rule);
|
const translator = new Translator(rule, setting);
|
||||||
|
|
||||||
// 监听消息
|
// 监听消息
|
||||||
browser?.runtime.onMessage.addListener(async ({ action, args }) => {
|
browser?.runtime.onMessage.addListener(async ({ action, args }) => {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
import { StoragesProvider } from "../hooks/Storage";
|
import { StoragesProvider } from "../hooks/Storage";
|
||||||
import { queryEls } from ".";
|
import { queryEls } from ".";
|
||||||
import Content from "../views/Content";
|
import Content from "../views/Content";
|
||||||
|
import { fetchUpdate } from "./fetch";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 翻译类
|
* 翻译类
|
||||||
@@ -44,7 +45,8 @@ export class Translator {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(rule) {
|
constructor(rule, { fetchInterval, fetchLimit }) {
|
||||||
|
fetchUpdate(fetchInterval, fetchLimit);
|
||||||
this.rule = rule;
|
this.rule = rule;
|
||||||
if (rule.transOpen === "true") {
|
if (rule.transOpen === "true") {
|
||||||
this._register();
|
this._register();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import ReactDOM from "react-dom/client";
|
|||||||
import Action from "./views/Action";
|
import Action from "./views/Action";
|
||||||
import createCache from "@emotion/cache";
|
import createCache from "@emotion/cache";
|
||||||
import { CacheProvider } from "@emotion/react";
|
import { CacheProvider } from "@emotion/react";
|
||||||
import { fetchUpdate } from "./libs/fetch";
|
|
||||||
import { getRules, matchRule } from "./libs";
|
import { getRules, matchRule } from "./libs";
|
||||||
import { getSetting } from "./libs";
|
import { getSetting } from "./libs";
|
||||||
import { Translator } from "./libs/translator";
|
import { Translator } from "./libs/translator";
|
||||||
@@ -33,11 +32,10 @@ import { Translator } from "./libs/translator";
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 翻译页面
|
// 翻译页面
|
||||||
const { fetchInterval, fetchLimit } = await getSetting();
|
const setting = await getSetting();
|
||||||
fetchUpdate(fetchInterval, fetchLimit);
|
|
||||||
const rules = await getRules();
|
const rules = await getRules();
|
||||||
const rule = matchRule(rules, document.location.href);
|
const rule = matchRule(rules, document.location.href);
|
||||||
const translator = new Translator(rule);
|
const translator = new Translator(rule, setting);
|
||||||
|
|
||||||
// 浮球按钮
|
// 浮球按钮
|
||||||
const $action = document.createElement("div");
|
const $action = document.createElement("div");
|
||||||
|
|||||||
Reference in New Issue
Block a user