modify entry func

This commit is contained in:
Gabe Yuan
2023-08-10 13:41:55 +08:00
parent 54ab126c64
commit 0616b4f221
3 changed files with 7 additions and 10 deletions

View File

@@ -6,19 +6,16 @@ import {
} from "./config";
import { getRules, matchRule } from "./libs";
import { getSetting } from "./libs";
import { fetchUpdate } from "./libs/fetch";
import { Translator } from "./libs/translator";
/**
* 入口函数
*/
(async () => {
const { fetchInterval, fetchLimit } = await getSetting();
fetchUpdate(fetchInterval, fetchLimit);
const setting = await getSetting();
const rules = await getRules();
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 }) => {

View File

@@ -9,6 +9,7 @@ import {
import { StoragesProvider } from "../hooks/Storage";
import { queryEls } from ".";
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;
if (rule.transOpen === "true") {
this._register();

View File

@@ -3,7 +3,6 @@ import ReactDOM from "react-dom/client";
import Action from "./views/Action";
import createCache from "@emotion/cache";
import { CacheProvider } from "@emotion/react";
import { fetchUpdate } from "./libs/fetch";
import { getRules, matchRule } from "./libs";
import { getSetting } from "./libs";
import { Translator } from "./libs/translator";
@@ -33,11 +32,10 @@ import { Translator } from "./libs/translator";
}
// 翻译页面
const { fetchInterval, fetchLimit } = await getSetting();
fetchUpdate(fetchInterval, fetchLimit);
const setting = await getSetting();
const rules = await getRules();
const rule = matchRule(rules, document.location.href);
const translator = new Translator(rule);
const translator = new Translator(rule, setting);
// 浮球按钮
const $action = document.createElement("div");