optimize some code
This commit is contained in:
2
dist/chrome/manifest.json
vendored
2
dist/chrome/manifest.json
vendored
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "__MSG_app_name__",
|
"name": "__MSG_app_name__",
|
||||||
"description": "__MSG_app_description__",
|
"description": "__MSG_app_description__",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"default_locale": "zh",
|
"default_locale": "zh",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||||
|
|||||||
2
dist/chrome/static/js/content.js
vendored
2
dist/chrome/static/js/content.js
vendored
File diff suppressed because one or more lines are too long
2
dist/edge/manifest.json
vendored
2
dist/edge/manifest.json
vendored
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "__MSG_app_name__",
|
"name": "__MSG_app_name__",
|
||||||
"description": "__MSG_app_description__",
|
"description": "__MSG_app_description__",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"default_locale": "zh",
|
"default_locale": "zh",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||||
|
|||||||
2
dist/edge/static/js/content.js
vendored
2
dist/edge/static/js/content.js
vendored
File diff suppressed because one or more lines are too long
2
dist/firefox/manifest.json
vendored
2
dist/firefox/manifest.json
vendored
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "__MSG_app_name__",
|
"name": "__MSG_app_name__",
|
||||||
"description": "__MSG_app_description__",
|
"description": "__MSG_app_description__",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"default_locale": "zh",
|
"default_locale": "zh",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||||
|
|||||||
2
dist/firefox/static/js/content.js
vendored
2
dist/firefox/static/js/content.js
vendored
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "__MSG_app_name__",
|
"name": "__MSG_app_name__",
|
||||||
"description": "__MSG_app_description__",
|
"description": "__MSG_app_description__",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"default_locale": "zh",
|
"default_locale": "zh",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "kiss-translator",
|
"name": "kiss-translator",
|
||||||
"description": "A simple translator extension",
|
"description": "A simple translator extension",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "__MSG_app_name__",
|
"name": "__MSG_app_name__",
|
||||||
"description": "__MSG_app_description__",
|
"description": "__MSG_app_description__",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"default_locale": "zh",
|
"default_locale": "zh",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import {
|
|||||||
MSG_TRANS_TOGGLE,
|
MSG_TRANS_TOGGLE,
|
||||||
MSG_TRANS_GETRULE,
|
MSG_TRANS_GETRULE,
|
||||||
MSG_TRANS_PUTRULE,
|
MSG_TRANS_PUTRULE,
|
||||||
|
OPT_TRANS_OPENAI,
|
||||||
|
TRANS_MIN_LENGTH,
|
||||||
|
TRANS_MAX_LENGTH,
|
||||||
} from "./config";
|
} from "./config";
|
||||||
import Content from "./views/Content";
|
import Content from "./views/Content";
|
||||||
import { StoragesProvider } from "./hooks/Storage";
|
import { StoragesProvider } from "./hooks/Storage";
|
||||||
@@ -100,10 +103,13 @@ class Translator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const q = el.innerHTML
|
// 除openai外,保留code和a标签
|
||||||
.replace(/<(?!\/?(code|a))[^>]+>/gi, "")
|
const q =
|
||||||
.trim();
|
this._rule.translator === OPT_TRANS_OPENAI
|
||||||
if (!q) {
|
? el.innerText.trim()
|
||||||
|
: el.innerHTML.replace(/<(?!\/?(code|a))[^>]+>/gi, "").trim();
|
||||||
|
if (!q || q.length < TRANS_MIN_LENGTH || q.length > TRANS_MAX_LENGTH) {
|
||||||
|
// 太长或太短不翻译
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import { useState } from "react";
|
|||||||
import { apiTranslate } from "../apis";
|
import { apiTranslate } from "../apis";
|
||||||
import browser from "../libs/browser";
|
import browser from "../libs/browser";
|
||||||
import {
|
import {
|
||||||
TRANS_MIN_LENGTH,
|
|
||||||
TRANS_MAX_LENGTH,
|
|
||||||
MSG_TRANS_PUTRULE,
|
MSG_TRANS_PUTRULE,
|
||||||
DEFAULT_FETCH_LIMIT,
|
DEFAULT_FETCH_LIMIT,
|
||||||
MSG_FETCH_LIMIT,
|
MSG_FETCH_LIMIT,
|
||||||
@@ -47,11 +45,6 @@ export function useTranslate(q, initRule) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
// 太长或太短不翻译
|
|
||||||
if (q.length < TRANS_MIN_LENGTH || q.length > TRANS_MAX_LENGTH) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const deLang = await detectLang(q);
|
const deLang = await detectLang(q);
|
||||||
|
|||||||
Reference in New Issue
Block a user