some minor modifications
This commit is contained in:
17
src/index.js
17
src/index.js
@@ -1,18 +1,31 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
import Divider from "@mui/material/Divider";
|
import Divider from "@mui/material/Divider";
|
||||||
import ReactMarkdown from "react-markdown";
|
import ReactMarkdown from "react-markdown";
|
||||||
import Paper from "@mui/material/Paper";
|
import Paper from "@mui/material/Paper";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
import { useFetch } from "./hooks/Fetch";
|
import { useFetch } from "./hooks/Fetch";
|
||||||
import { I18N, URL_RAW_PREFIX } from "./config";
|
import { I18N, URL_RAW_PREFIX } from "./config";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const [lang, setLang] = useState("zh");
|
||||||
const [data, loading, error] = useFetch(
|
const [data, loading, error] = useFetch(
|
||||||
`${URL_RAW_PREFIX}/${I18N?.["about_md"]?.["zh"]}`
|
`${URL_RAW_PREFIX}/${I18N?.["about_md"]?.[lang]}`
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<Paper sx={{ padding: 2, margin: 2 }}>
|
<Paper sx={{ padding: 2, margin: 2 }}>
|
||||||
|
<Stack spacing={2} direction="row" justifyContent="flex-end">
|
||||||
|
<Button
|
||||||
|
variant="text"
|
||||||
|
onClick={() => {
|
||||||
|
setLang((pre) => (pre === "zh" ? "en" : "zh"));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{lang === "zh" ? "ENGLISH" : "中文"}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
<Divider>{`KISS Translator v${process.env.REACT_APP_VERSION}`}</Divider>
|
<Divider>{`KISS Translator v${process.env.REACT_APP_VERSION}`}</Divider>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<center>
|
<center>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { CacheProvider } from "@emotion/react";
|
|||||||
import { getSetting, getRules, matchRule, getFab } from "./libs";
|
import { getSetting, getRules, matchRule, getFab } from "./libs";
|
||||||
import { Translator } from "./libs/translator";
|
import { Translator } from "./libs/translator";
|
||||||
import { trySyncAllSubRules } from "./libs/rules";
|
import { trySyncAllSubRules } from "./libs/rules";
|
||||||
|
import { isGm } from "./libs/browser";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 入口函数
|
* 入口函数
|
||||||
@@ -57,6 +58,7 @@ import { trySyncAllSubRules } from "./libs/rules";
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 注册菜单
|
// 注册菜单
|
||||||
|
if (isGm) {
|
||||||
GM.registerMenuCommand(
|
GM.registerMenuCommand(
|
||||||
"Toggle Translate",
|
"Toggle Translate",
|
||||||
(event) => {
|
(event) => {
|
||||||
@@ -71,6 +73,7 @@ import { trySyncAllSubRules } from "./libs/rules";
|
|||||||
},
|
},
|
||||||
"C"
|
"C"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 同步订阅规则
|
// 同步订阅规则
|
||||||
trySyncAllSubRules(setting);
|
trySyncAllSubRules(setting);
|
||||||
|
|||||||
@@ -638,6 +638,7 @@ function SubRulesEdit({ subrules }) {
|
|||||||
const [inputText, setInputText] = useState("");
|
const [inputText, setInputText] = useState("");
|
||||||
const [inputError, setInputError] = useState("");
|
const [inputError, setInputError] = useState("");
|
||||||
const [showInput, setShowInput] = useState(false);
|
const [showInput, setShowInput] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const handleCancel = (e) => {
|
const handleCancel = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -661,6 +662,7 @@ function SubRulesEdit({ subrules }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setLoading(true);
|
||||||
const rules = await syncSubRules(url);
|
const rules = await syncSubRules(url);
|
||||||
if (rules.length === 0) {
|
if (rules.length === 0) {
|
||||||
throw new Error("empty rules");
|
throw new Error("empty rules");
|
||||||
@@ -671,6 +673,8 @@ function SubRulesEdit({ subrules }) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[fetch rules]", err);
|
console.log("[fetch rules]", err);
|
||||||
setInputError(i18n("error_fetch_url"));
|
setInputError(i18n("error_fetch_url"));
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -713,7 +717,12 @@ function SubRulesEdit({ subrules }) {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Stack direction="row" alignItems="center" spacing={2}>
|
<Stack direction="row" alignItems="center" spacing={2}>
|
||||||
<Button size="small" variant="contained" onClick={handleSave}>
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="contained"
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
{i18n("save")}
|
{i18n("save")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button size="small" variant="outlined" onClick={handleCancel}>
|
<Button size="small" variant="outlined" onClick={handleCancel}>
|
||||||
|
|||||||
Reference in New Issue
Block a user