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