userscript...
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import Options from "./views/Options";
|
import Options from "./views/Options";
|
||||||
|
import Action from "./views/Action";
|
||||||
|
import createCache from "@emotion/cache";
|
||||||
|
import { CacheProvider } from "@emotion/react";
|
||||||
|
|
||||||
import { browser } from "./libs/browser";
|
import { browser } from "./libs/browser";
|
||||||
import {
|
import {
|
||||||
@@ -13,6 +16,33 @@ import { getSetting } from "./libs";
|
|||||||
import { transPool } from "./libs/pool";
|
import { transPool } from "./libs/pool";
|
||||||
import { Translator } from "./libs/translator";
|
import { Translator } from "./libs/translator";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义元素
|
||||||
|
*/
|
||||||
|
class ActionElement extends HTMLElement {
|
||||||
|
connectedCallback() {
|
||||||
|
const shadowContainer = this.attachShadow({ mode: "open" });
|
||||||
|
const emotionRoot = document.createElement("style");
|
||||||
|
const shadowRootElement = document.createElement("div");
|
||||||
|
shadowContainer.appendChild(emotionRoot);
|
||||||
|
shadowContainer.appendChild(shadowRootElement);
|
||||||
|
|
||||||
|
const cache = createCache({
|
||||||
|
key: "css",
|
||||||
|
prepend: true,
|
||||||
|
container: emotionRoot,
|
||||||
|
});
|
||||||
|
|
||||||
|
ReactDOM.createRoot(shadowRootElement).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<CacheProvider value={cache}>
|
||||||
|
<Action />
|
||||||
|
</CacheProvider>
|
||||||
|
</React.StrictMode>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 入口函数
|
* 入口函数
|
||||||
*/
|
*/
|
||||||
@@ -28,9 +58,15 @@ import { Translator } from "./libs/translator";
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 插入按钮
|
||||||
|
const actionName = "kiss-action";
|
||||||
|
customElements.define(actionName, ActionElement);
|
||||||
|
const $action = document.createElement(actionName);
|
||||||
|
document.body.parentElement.appendChild($action);
|
||||||
|
|
||||||
|
// 翻译页面
|
||||||
const { fetchInterval, fetchLimit } = await getSetting();
|
const { fetchInterval, fetchLimit } = await getSetting();
|
||||||
transPool.update(fetchInterval, fetchLimit);
|
transPool.update(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);
|
||||||
|
|||||||
16
src/views/Action/index.js
Normal file
16
src/views/Action/index.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Fab from "@mui/material/Fab";
|
||||||
|
import AddIcon from "@mui/icons-material/Add";
|
||||||
|
import ThemeProvider from "../../hooks/Theme";
|
||||||
|
|
||||||
|
export default function Action() {
|
||||||
|
return (
|
||||||
|
<ThemeProvider>
|
||||||
|
<Box style={{ position: "fixed", top: 16, right: 16, zIndex: 10001 }}>
|
||||||
|
<Fab color="primary">
|
||||||
|
<AddIcon />
|
||||||
|
</Fab>
|
||||||
|
</Box>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user