Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2650e5cf7c | ||
|
|
da1fa3e8ed | ||
|
|
e256314d4f | ||
|
|
f8f7d5955f | ||
|
|
fa6f68fec3 | ||
|
|
0705e8a65a | ||
|
|
9d9bbd3821 | ||
|
|
86a312ea6b | ||
|
|
e4771e795b | ||
|
|
1504830142 | ||
|
|
7e99bc7aad | ||
|
|
abca8cb26d | ||
|
|
d032088415 | ||
|
|
80fb26ad48 | ||
|
|
017db589d4 | ||
|
|
6e1b842bba | ||
|
|
0c04ea3a33 | ||
|
|
c21ac1aea6 |
2
.env
2
.env
@@ -2,7 +2,7 @@ GENERATE_SOURCEMAP=false
|
||||
|
||||
REACT_APP_NAME=KISS Translator
|
||||
REACT_APP_NAME_CN=简约翻译
|
||||
REACT_APP_VERSION=2.0.10
|
||||
REACT_APP_VERSION=2.0.12
|
||||
|
||||
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
||||
|
||||
|
||||
10
README.en.md
10
README.en.md
@@ -73,11 +73,11 @@ A simple, open source [bilingual translation extension & Greasemonkey script](ht
|
||||
> - Grease Monkey script will encounter more usage problems (cross domain issues, script conflicts, etc.)
|
||||
|
||||
- [x] Browser extension
|
||||
- [x] Chrome [Installation address](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=zh-CN)
|
||||
- [x] Chrome [Installation address](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=en)
|
||||
- [x] Kiwi (Android)
|
||||
- [x] Orion (iOS)
|
||||
- [x] Edge [Installation address](https://microsoftedge.microsoft.com/addons/detail/%E7%AE%80%E7%BA%A6%E7%BF%BB%E8%AF%91/jemckldkclkinpjighnoilpbldbdmmlh?hl=zh-CN)
|
||||
- [x] Firefox [Installation address](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/)
|
||||
- [x] Edge [Installation address](https://microsoftedge.microsoft.com/addons/detail/%E7%AE%80%E7%BA%A6%E7%BF%BB%E8%AF%91/jemckldkclkinpjighnoilpbldbdmmlh?hl=en)
|
||||
- [x] Firefox [Installation address](https://addons.mozilla.org/en-US/firefox/addon/kiss-translator/)
|
||||
- [ ] Safari
|
||||
- [ ] Safari (Mac)
|
||||
- [ ] Safari (iOS)
|
||||
@@ -141,10 +141,6 @@ Example reference: [custom-api_v2.md](https://github.com/fishjar/kiss-translator
|
||||
|
||||
Settings page address: https://fishjar.github.io/kiss-translator/options.html
|
||||
|
||||
### Subtitle Translation Tips
|
||||
|
||||
As long as the KT button is on (blue background with white text), you don't need to click it multiple times. Just click the original subtitle button in the YouTube player and wait for the bilingual subtitles to appear automatically.
|
||||
|
||||
## Future Plans
|
||||
|
||||
This is a side project with no strict timeline. Community contributions are welcome. The following are preliminary feature directions:
|
||||
|
||||
10
README.ja.md
10
README.ja.md
@@ -73,11 +73,11 @@
|
||||
> - ユーザースクリプトはより多くの問題(クロスドメイン問題、スクリプトの競合など)に遭遇する可能性があります
|
||||
|
||||
- [x] ブラウザ拡張機能
|
||||
- [x] Chrome [インストール](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=zh-CN)
|
||||
- [x] Chrome [インストール](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=ja)
|
||||
- [x] Kiwi (Android)
|
||||
- [x] Orion (iOS)
|
||||
- [x] Edge [インストール](https://microsoftedge.microsoft.com/addons/detail/%E7%AE%80%E7%BA%A6%E7%BF%BB%E8%AF%91/jemckldkclkinpjighnoilpbldbdmmlh?hl=zh-CN)
|
||||
- [x] Firefox [インストール](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/)
|
||||
- [x] Edge [インストール](https://microsoftedge.microsoft.com/addons/detail/%E7%AE%80%E7%BA%A6%E7%BF%BB%E8%AF%91/jemckldkclkinpjighnoilpbldbdmmlh?hl=ja)
|
||||
- [x] Firefox [インストール](https://addons.mozilla.org/ja/firefox/addon/kiss-translator/)
|
||||
- [ ] Safari
|
||||
- [ ] Safari (Mac)
|
||||
- [ ] Safari (iOS)
|
||||
@@ -141,10 +141,6 @@ APIテストの失敗には、一般的に以下の原因が考えられます
|
||||
|
||||
設定ページアドレス: https://fishjar.github.io/kiss-translator/options.html
|
||||
|
||||
### 字幕翻訳のヒント
|
||||
|
||||
KTボタンがオンの状態(青地に白文字)であれば、何度もクリックする必要はありません。Youtubeプレーヤーの字幕ボタンをクリックしてオンにするだけで、バイリンガル字幕が自動的に表示されるのを待つだけです。
|
||||
|
||||
## 今後の計画
|
||||
|
||||
本プロジェクトは余暇に開発しており、厳密なタイムスケジュールはありません。コミュニティの共同構築を歓迎します。以下は初期段階の機能の方向性です:
|
||||
|
||||
10
README.ko.md
10
README.ko.md
@@ -73,11 +73,11 @@
|
||||
> - 유저 스크립트는 사용상 더 많은 문제 (크로스 도메인 문제, 스크립트 충돌 등)를 겪을 수 있습니다.
|
||||
|
||||
- [x] 브라우저 확장 프로그램
|
||||
- [x] Chrome [설치 주소](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=zh-CN)
|
||||
- [x] Chrome [설치 주소](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=ko)
|
||||
- [x] Kiwi (Android)
|
||||
- [x] Orion (iOS)
|
||||
- [x] Edge [설치 주소](https://microsoftedge.microsoft.com/addons/detail/%E7%AE%80%E7%BA%A6%E7%BF%BB%E8%AF%91/jemckldkclkinpjighnoilpbldbdmmlh?hl=zh-CN)
|
||||
- [x] Firefox [설치 주소](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/)
|
||||
- [x] Edge [설치 주소](https://microsoftedge.microsoft.com/addons/detail/%E7%AE%80%E7%BA%A6%E7%BF%BB%E8%AF%91/jemckldkclkinpjighnoilpbldbdmmlh?hl=ko)
|
||||
- [x] Firefox [설치 주소](https://addons.mozilla.org/ko/firefox/addon/kiss-translator/)
|
||||
- [ ] Safari
|
||||
- [ ] Safari (Mac)
|
||||
- [ ] Safari (iOS)
|
||||
@@ -141,10 +141,6 @@
|
||||
|
||||
설정 페이지 주소: https://fishjar.github.io/kiss-translator/options.html
|
||||
|
||||
### 자막 번역 팁
|
||||
|
||||
KT 버튼이 켜진 상태(파란 바탕에 흰 글씨)이기만 하면, 여러 번 클릭할 필요 없이 Youtube 플레이어의 원래 자막 버튼을 클릭하여 켜기만 하면 이중 언어 자막이 자동으로 나타날 때까지 기다리면 됩니다.
|
||||
|
||||
## 향후 계획
|
||||
|
||||
본 프로젝트는 여가 시간에 개발되며, 엄격한 시간표는 없습니다. 커뮤니티의 공동 구축을 환영합니다. 다음은 초기 구상 중인 기능 방향입니다:
|
||||
|
||||
@@ -141,10 +141,6 @@
|
||||
|
||||
设置页面地址: https://fishjar.github.io/kiss-translator/options.html
|
||||
|
||||
### 字幕翻译小技巧
|
||||
|
||||
KT按钮只要是开启状态(蓝底白字),无需多次点击,只需点击开启Youtube播放器本来的字幕按钮,然后等待双语字幕自动呈现即可。
|
||||
|
||||
## 未来规划
|
||||
|
||||
本项目为业余开发,无严格时间表,欢迎社区共建。以下为初步设想的功能方向:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "kiss-translator",
|
||||
"description": "A minimalist bilingual translation Extension & Greasemonkey Script",
|
||||
"version": "2.0.10",
|
||||
"version": "2.0.12",
|
||||
"author": "Gabe<yugang2002@gmail.com>",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -4,321 +4,11 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>%REACT_APP_NAME%</title>
|
||||
<style>
|
||||
img {
|
||||
width: 1.2em;
|
||||
height: 1.2em;
|
||||
}
|
||||
|
||||
svg {
|
||||
max-width: 1.2em;
|
||||
max-height: 1.2em;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// (() => {
|
||||
// var shadow = document.querySelector("#shadow1");
|
||||
// var root = shadow.attachShadow({ mode: "open" });
|
||||
// var newLine = document.createElement("p");
|
||||
// newLine.innerText = "new line";
|
||||
// root.appendChild(newLine);
|
||||
// })();
|
||||
|
||||
// setTimeout(function () {
|
||||
// var shadow = document.querySelector("#shadow2");
|
||||
// var root = shadow.attachShadow({ mode: "open" });
|
||||
// }, 1000);
|
||||
|
||||
// setTimeout(() => {
|
||||
// var newLine = document.createElement("p");
|
||||
// newLine.innerText = "new line";
|
||||
// var shadow = document.querySelector("#shadow2");
|
||||
// shadow.shadowRoot.appendChild(newLine);
|
||||
// }, 2000);
|
||||
|
||||
// setTimeout(() => {
|
||||
// var newLine = document.createElement("div");
|
||||
// newLine.innerHTML = "<p>second line</p><p>third line</p>";
|
||||
// var shadow = document.querySelector("#shadow2");
|
||||
// shadow.shadowRoot.appendChild(newLine);
|
||||
// }, 3000);
|
||||
|
||||
// setTimeout(function () {
|
||||
// var el = document.querySelector("h2");
|
||||
// el.innerText = "hello world";
|
||||
|
||||
// var title = document.querySelector("#addtitle");
|
||||
// title.innerHTML =
|
||||
// "<div><p>second title</p><ul><li>second title</li><li><p>second title</p></li></ul></div>";
|
||||
// }, 1000);
|
||||
|
||||
setTimeout(function () {
|
||||
var el = document.querySelector('h2>p>span');
|
||||
el.innerText = 'hello world';
|
||||
}, 1000);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root">
|
||||
<p>You need to enable <code>JavaScript</code> to run <span>this app.</span></p>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<div id="content">
|
||||
<p>You need to enable JavaScript to run <span>this app.</span></p>
|
||||
The <span>embargo</span> has just lifted to confirm that AmpereOne is coming to
|
||||
Google Cloud with the C3A instances.
|
||||
<br />
|
||||
But these upcoming instances for now are only in private preview form.
|
||||
<br />
|
||||
<br />
|
||||
Needless to say I also haven't had any AmpereOne access to check out the
|
||||
performance and power efficiency of these new Arm server processors from Ampere
|
||||
Computing.
|
||||
<br />
|
||||
</div>
|
||||
<h2>
|
||||
<p>
|
||||
<span>React is a JavaScript library for building user interfaces.</span>
|
||||
</p>
|
||||
</h2>
|
||||
<hr />
|
||||
<input id="input1" style="width: 80%" />
|
||||
<hr />
|
||||
<textarea id="textarea1" style="width: 80%">test</textarea>
|
||||
<hr />
|
||||
<div id="addtitle"></div>
|
||||
<h2>Shadow 1</h2>
|
||||
<div id="shadow1"></div>
|
||||
<h2>Shadow 2</h2>
|
||||
<div id="shadow2"></div>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<h2>
|
||||
React Server Components (or RSC) is a new application architecture designed by the
|
||||
React team.
|
||||
</h2>
|
||||
<iframe
|
||||
id="iframe1"
|
||||
width="800px"
|
||||
height="600px"
|
||||
src="http://localhost:3000/index.html"></iframe>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<h2>We’ve first shared our research on RSC in an introductory talk and an RFC.</h2>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<h2>
|
||||
To recap them, we are introducing a new kind of component—Server Components—that
|
||||
run ahead of time and are excluded from your JavaScript bundle.
|
||||
</h2>
|
||||
<iframe id="iframe2" width="800px" height="600px" src="https://react.dev/"></iframe>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<div class="cont cont1">
|
||||
<h2>
|
||||
Server Components can run during the build, letting you read from the filesystem
|
||||
or fetch static content.
|
||||
</h2>
|
||||
<ul>
|
||||
<li>
|
||||
They can also run on the server, letting you access your data layer without
|
||||
having to build an API. You can pass data by props from Server Components to
|
||||
the interactive Client Components in the browser.
|
||||
</li>
|
||||
<li>以声明式编写 UI,可以让你的代码更加可靠,且方便调试。</li>
|
||||
</ul>
|
||||
</div>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<div class="cont cont2">
|
||||
<h2>
|
||||
Since our last update, we have merged the React Server Components RFC to ratify
|
||||
the proposal.
|
||||
</h2>
|
||||
<ul>
|
||||
<li>
|
||||
RSC combines the simple “request/response” mental model of server-centric
|
||||
Multi-Page Apps with the seamless interactivity of client-centric Single-Page
|
||||
Apps, giving you the best of both worlds.
|
||||
</li>
|
||||
<li>
|
||||
React 使创建交互式 UI
|
||||
变得轻而易举。为你应用的每一个状态设计简洁的视图,当数据变动时 React
|
||||
能高效更新并渲染合适的组件。
|
||||
</li>
|
||||
<li>以声明式编写 UI,可以让你的代码更加可靠,且方便调试。</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"manifest_version": 2,
|
||||
"name": "__MSG_app_name__",
|
||||
"description": "__MSG_app_description__",
|
||||
"version": "2.0.10",
|
||||
"version": "2.0.12",
|
||||
"default_locale": "en",
|
||||
"author": "Gabe<yugang2002@gmail.com>",
|
||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"manifest_version": 3,
|
||||
"name": "__MSG_app_name__",
|
||||
"description": "__MSG_app_description__",
|
||||
"version": "2.0.10",
|
||||
"version": "2.0.12",
|
||||
"default_locale": "en",
|
||||
"author": "Gabe<yugang2002@gmail.com>",
|
||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"manifest_version": 2,
|
||||
"name": "__MSG_app_name__",
|
||||
"description": "__MSG_app_description__",
|
||||
"version": "2.0.10",
|
||||
"version": "2.0.12",
|
||||
"default_locale": "en",
|
||||
"author": "Gabe<yugang2002@gmail.com>",
|
||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||
|
||||
@@ -739,6 +739,13 @@ export const genTransReq = async ({ reqHook, ...args }) => {
|
||||
// 执行 request hook
|
||||
if (reqHook?.trim() && !events) {
|
||||
try {
|
||||
const req = {
|
||||
url,
|
||||
body,
|
||||
headers,
|
||||
userMsg,
|
||||
method,
|
||||
};
|
||||
interpreter.run(`exports.reqHook = ${reqHook}`);
|
||||
const hookResult = await interpreter.exports.reqHook(
|
||||
{
|
||||
@@ -747,20 +754,16 @@ export const genTransReq = async ({ reqHook, ...args }) => {
|
||||
defaultSubtitlePrompt,
|
||||
defaultNobatchPrompt,
|
||||
defaultNobatchUserPrompt,
|
||||
req,
|
||||
},
|
||||
{
|
||||
url,
|
||||
body,
|
||||
headers,
|
||||
userMsg,
|
||||
method,
|
||||
}
|
||||
req
|
||||
);
|
||||
if (hookResult && hookResult.url) {
|
||||
return genInit(hookResult);
|
||||
}
|
||||
} catch (err) {
|
||||
kissLog("run req hook", err);
|
||||
throw new Error(`Request hook error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -817,6 +820,7 @@ export const parseTransRes = async (
|
||||
}
|
||||
} catch (err) {
|
||||
kissLog("run res hook", err);
|
||||
throw new Error(`Response hook error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ import {
|
||||
MSG_UPDATE_CSP,
|
||||
MSG_BUILTINAI_DETECT,
|
||||
MSG_BUILTINAI_TRANSLATE,
|
||||
DEFAULT_CSPLIST,
|
||||
DEFAULT_ORILIST,
|
||||
CMD_TOGGLE_TRANSLATE,
|
||||
CMD_TOGGLE_STYLE,
|
||||
CMD_OPEN_OPTIONS,
|
||||
@@ -37,7 +35,7 @@ import { injectInlineJsBg, injectInternalCss } from "./libs/injector";
|
||||
import { kissLog, logger } from "./libs/log";
|
||||
import { chromeDetect, chromeTranslate } from "./libs/builtinAI";
|
||||
|
||||
globalThis.ContextType = "BACKGROUND";
|
||||
globalThis.__KISS_CONTEXT__ = "background";
|
||||
|
||||
const CSP_RULE_START_ID = 1;
|
||||
const ORI_RULE_START_ID = 10000;
|
||||
@@ -193,19 +191,21 @@ async function registerMsgDisplayScript() {
|
||||
/**
|
||||
* 插件安装
|
||||
*/
|
||||
browser.runtime.onInstalled.addListener(() => {
|
||||
tryInitDefaultData();
|
||||
browser.runtime.onInstalled.addListener(async () => {
|
||||
await tryInitDefaultData();
|
||||
|
||||
//在thunderbird中注册脚本
|
||||
if (process.env.REACT_APP_CLIENT === CLIENT_THUNDERBIRD) {
|
||||
registerMsgDisplayScript();
|
||||
}
|
||||
|
||||
const { contextMenuType, csplist, orilist } = await getSettingWithDefault();
|
||||
|
||||
// 右键菜单
|
||||
addContextMenus();
|
||||
addContextMenus(contextMenuType);
|
||||
|
||||
// 禁用CSP
|
||||
updateCspRules({ csplist: DEFAULT_CSPLIST, orilist: DEFAULT_ORILIST });
|
||||
updateCspRules({ csplist, orilist });
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,20 +118,22 @@ async function getFavWords(rule) {
|
||||
*/
|
||||
export async function run(isUserscript = false) {
|
||||
try {
|
||||
// if (document?.documentElement?.tagName?.toUpperCase() !== "HTML") {
|
||||
// return;
|
||||
// }
|
||||
if (!document?.contentType?.includes("text")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取设置信息
|
||||
const setting = await getSettingWithDefault();
|
||||
|
||||
// 日志
|
||||
logger.setLevel(setting.logLevel);
|
||||
|
||||
const href = document.location.href;
|
||||
// if (document?.documentElement?.tagName?.toUpperCase() !== "HTML") {
|
||||
// return;
|
||||
// }
|
||||
const contentType = document?.contentType?.toLowerCase() || "";
|
||||
if (!contentType.includes("text") && !contentType.includes("html")) {
|
||||
logger.info("Skip running in document content type: ", contentType);
|
||||
return;
|
||||
}
|
||||
|
||||
const href = document?.location?.href || "";
|
||||
|
||||
// 设置页面
|
||||
if (
|
||||
|
||||
@@ -2,402 +2,708 @@ const quotes = [
|
||||
{
|
||||
en: "The unexamined life is not worth living.",
|
||||
zh: "未经审视的人生不值得过。",
|
||||
zh_TW: "未經審視的人生不值得過。",
|
||||
ja: "吟味されない人生は生きるに値しない。",
|
||||
ko: "성찰하지 않는 삶은 살 가치가 없다。",
|
||||
},
|
||||
{
|
||||
en: "I think, therefore I am.",
|
||||
zh: "我思故我在。",
|
||||
zh_TW: "我思故我在。",
|
||||
ja: "我思う、ゆえに我あり。",
|
||||
ko: "나는 생각한다, 고로 존재한다。",
|
||||
},
|
||||
{
|
||||
en: "He who has a why to live for can bear almost any how.",
|
||||
zh: "知道为何而活的人,几乎能忍受任何一种生活。",
|
||||
zh_TW: "知道為何而活的人,幾乎能忍受任何一種生活。",
|
||||
ja: "生きるための「なぜ」を持つ者は、ほとんどあらゆる「どのように」にも耐えることができる。",
|
||||
ko: "살아야 할 이유를 아는 사람은 거의 모든 상황을 견딜 수 있다。",
|
||||
},
|
||||
{
|
||||
en: "Life is what happens when you're busy making other plans.",
|
||||
zh: "生活就是当你忙着制定其他计划时所发生的事情。",
|
||||
zh_TW: "生活就是當你忙著制定其他計劃時所發生的事情。",
|
||||
ja: "人生とは、他の計画を立てるのに忙しいときに起こるものだ。",
|
||||
ko: "인생은 다른 계획을 세우느라 바쁠 때 일어나는 일이다。",
|
||||
},
|
||||
{
|
||||
en: "Get busy living or get busy dying.",
|
||||
zh: "要么忙着活,要么忙着死。",
|
||||
zh_TW: "要么忙著活,要么忙著死。",
|
||||
ja: "必死に生きるか、必死に死ぬかだ。",
|
||||
ko: "바쁘게 살거나, 바쁘게 죽거나。",
|
||||
},
|
||||
{
|
||||
en: "We are what we repeatedly do. Excellence, then, is not an act, but a habit.",
|
||||
zh: "我们由我们反复做的事情构成的。因此,卓越不是一种行为,而是一种习惯。",
|
||||
zh_TW:
|
||||
"我們由我們反覆做的事情構成的。因此,卓越不是一種行為,而是一種習慣。",
|
||||
ja: "我々は繰り返し行うことの集大成である。卓越とは行為ではなく、習慣なのだ。",
|
||||
ko: "우리는 우리가 반복적으로 하는 일의 결과물이다. 그렇다면 탁월함은 행동이 아니라 습관이다。",
|
||||
},
|
||||
{
|
||||
en: "Man is condemned to be free.",
|
||||
zh: "人注定是自由的。",
|
||||
zh_TW: "人註定是自由的。",
|
||||
ja: "人間は自由であるように呪われている。",
|
||||
ko: "인간은 자유롭도록 저주받았다。",
|
||||
},
|
||||
{
|
||||
en: "To be, or not to be: that is the question.",
|
||||
zh: "生存还是毁灭,这是一个问题。",
|
||||
zh_TW: "生存還是毀滅,這是一個問題。",
|
||||
ja: "生きるべきか、死ぬべきか、それが問題だ。",
|
||||
ko: "죽느냐 사느냐, 그것이 문제로다。",
|
||||
},
|
||||
{
|
||||
en: "The purpose of life is not to be happy. It is to be useful, to be honorable, to be compassionate, to have it make some difference that you have lived and lived well.",
|
||||
zh: "人生的目的不是快乐,而是有用、高尚、富有同情心,让你活过并且活得好,从而使世界有所不同。",
|
||||
zh_TW:
|
||||
"人生的目的不是快樂,而是有用、高尚、富有同情心,讓你活過並且活得好,從而使世界有所不同。",
|
||||
ja: "人生(じんせい)の目的(もくてき)は幸(しあわ)せになることではない。役(やく)に立(た)つこと、名誉(めいよ)あること、思(おも)いやりを持(も)つこと、そして自分(じぶん)が生(い)きてきたこと、よく生(い)きたことが何(なに)かの違(ちが)いをもたらすようにすることだ。",
|
||||
ko: "삶의 목적은 행복해지는 것이 아니다. 유용하고, 명예롭고, 자비로우며, 당신이 살았고 잘 살았다는 것이 어떤 차이를 만들도록 하는 것이다。",
|
||||
},
|
||||
{
|
||||
en: "Life is 10% what happens to us and 90% how we react to it.",
|
||||
zh: "生活 10% 取决于发生在我们身上的事,90% 取决于我们如何反应。",
|
||||
zh_TW: "生活 10% 取決於發生在我們身上的事,90% 取決於我們如何反應。",
|
||||
ja: "人生は、我々に起こることが10%で、それにどう反応するかが90%だ。",
|
||||
ko: "인생은 우리에게 일어나는 일이 10%이고, 그 일에 대해 우리가 어떻게 반응하느냐가 90%이다。",
|
||||
},
|
||||
{
|
||||
en: "The two most important days in your life are the day you are born and the day you find out why.",
|
||||
zh: "你一生中最重要的两天是:你出生的那天和你明白你为何出生的那天。",
|
||||
zh_TW: "你一生中最重要的兩天是:你出生的那天和你明白你為何出生的那天。",
|
||||
ja: "人生で最も重要な日は二日ある。生まれた日と、なぜ生まれたかを悟る日だ。",
|
||||
ko: "당신의 인생에서 가장 중요한 날은 두 번이다. 당신이 태어난 날과 그 이유를 깨닫는 날이다。",
|
||||
},
|
||||
{
|
||||
en: "In three words I can sum up everything I've learned about life: it goes on.",
|
||||
zh: "关于人生,我所学到的一切可以总结为三个词:它在继续。",
|
||||
zh_TW: "關於人生,我所學到的一切可以總結為三個詞:它在繼續。",
|
||||
ja: "人生について学んだすべてを3語でまとめることができる。それは「それでも続く」ということだ。",
|
||||
ko: "내가 인생에 대해 배운 모든 것을 세 단어로 요약할 수 있다: '삶은 계속된다'는 것이다。",
|
||||
},
|
||||
{
|
||||
en: "Not all those who wander are lost.",
|
||||
zh: "并非所有流浪者都迷失了方向。",
|
||||
zh_TW: "並非所有流浪者都迷失了方向。",
|
||||
ja: "さまよう者がすべて道に迷っているわけではない。",
|
||||
ko: "방황하는 자가 다 길을 잃은 것은 아니다。",
|
||||
},
|
||||
{
|
||||
en: "Life is simple, but we insist on making it complicated.",
|
||||
zh: "生活本简单,但我们坚持要把它弄复杂。",
|
||||
zh_TW: "生活本簡單,但我們堅持要把它弄複雜。",
|
||||
ja: "人生はシンプルだ。だが我々はそれを複雑にしようと躍起になる。",
|
||||
ko: "인생은 단순하지만, 우리가 복잡하게 만들기를 고집한다。",
|
||||
},
|
||||
{
|
||||
en: "Our life is what our thoughts make it.",
|
||||
zh: "我们的生活是由我们的思想造成的。",
|
||||
zh_TW: "我們的生活是由我們的思想造成的。",
|
||||
ja: "我々の人生は、我々の思考が作るものだ。",
|
||||
ko: "우리의 삶은 우리의 생각이 만드는 것이다。",
|
||||
},
|
||||
{
|
||||
en: "Find purpose, the means will follow.",
|
||||
zh: "找到目标,方法自会随之而来。",
|
||||
zh_TW: "找到目標,方法自會隨之而來。",
|
||||
ja: "目的を見つけよ、手段は後からついてくる。",
|
||||
ko: "목적을 찾으라, 수단은 따라올 것이다。",
|
||||
},
|
||||
{
|
||||
en: "The goal of life is living in agreement with nature.",
|
||||
zh: "生活的目标是与自然和谐相处。",
|
||||
zh_TW: "生活的目標是與自然和諧相處。",
|
||||
ja: "人生の目標は、自然と調和して生きることである。",
|
||||
ko: "삶의 목표는 자연과 조화를 이루며 사는 것이다。",
|
||||
},
|
||||
{
|
||||
en: "The only true wisdom is in knowing you know nothing.",
|
||||
zh: "唯一的真正智慧在于知道自己一无所有。",
|
||||
zh_TW: "唯一的真正智慧在於知道自己一無所有。",
|
||||
ja: "唯一真の知恵は、自分が何も知らないことを知ることにある。",
|
||||
ko: "유일한 참된 지혜는 자신이 아무것도 모른다는 것을 아는 것이다。",
|
||||
},
|
||||
{
|
||||
en: "Knowledge is power.",
|
||||
zh: "知识就是力量。",
|
||||
zh_TW: "知識就是力量。",
|
||||
ja: "知識は力なり。",
|
||||
ko: "아는 것이 힘이다。",
|
||||
},
|
||||
{
|
||||
en: "Knowing yourself is the beginning of all wisdom.",
|
||||
zh: "了解自己是所有智慧的开端。",
|
||||
zh_TW: "了解自己是所有智慧的開端。",
|
||||
ja: "自分自身を知ることが、すべての知恵の始まりである。",
|
||||
ko: "자신을 아는 것이 모든 지혜의 시작이다。",
|
||||
},
|
||||
{
|
||||
en: "The journey of a thousand miles begins with a single step.",
|
||||
zh: "千里之行,始于足下。",
|
||||
zh_TW: "千里之行,始於足下。",
|
||||
ja: "千里の道も一歩から。",
|
||||
ko: "천 리 길도 한 걸음부터。",
|
||||
},
|
||||
{
|
||||
en: "The only source of knowledge is experience.",
|
||||
zh: "知识的唯一来源是经验。",
|
||||
zh_TW: "知識的唯一來源是經驗。",
|
||||
ja: "知識の唯一の源泉は経験である。",
|
||||
ko: "지식의 유일한 원천은 경험이다。",
|
||||
},
|
||||
{
|
||||
en: "A fool thinks himself to be wise, but a wise man knows himself to be a fool.",
|
||||
zh: "愚者自以为聪明,智者自知愚蠢。",
|
||||
zh_TW: "愚者自以為聰明,智者自知愚蠢。",
|
||||
ja: "愚か者は自分を賢いと思うが、賢い者は自分が愚かであることを知っている。",
|
||||
ko: "바보는 자신이 현명하다고 생각하지만, 현명한 사람은 자신이 바보라는 것을 안다。",
|
||||
},
|
||||
{
|
||||
en: "We learn from failure, not from success!",
|
||||
zh: "我们从失败中学习,而不是从成功中!",
|
||||
zh_TW: "我們從失敗中學習,而不是從成功中!",
|
||||
ja: "我々は成功からではなく、失敗から学ぶ!",
|
||||
ko: "우리는 성공이 아닌, 실패로부터 배운다!",
|
||||
},
|
||||
{
|
||||
en: "The wise man is one who knows what he does not know.",
|
||||
zh: "智者,知其所不知。",
|
||||
zh_TW: "智者,知其所不知。",
|
||||
ja: "賢い者とは、自分が何を知らないかを知っている者である。",
|
||||
ko: "현명한 사람은 자신이 모르는 것을 아는 사람이다。",
|
||||
},
|
||||
{
|
||||
en: "To know that we know what we know, and that we do not know what we do not know, that is true knowledge.",
|
||||
zh: "知之为知之,不知为不知,是知也。",
|
||||
zh_TW: "知之為知之,不知為不知,是知也。",
|
||||
ja: "知るを知るとなし、知らざるを知らずとなす、これ知るなり。",
|
||||
ko: "아는 것을 안다고 하고, 모르는 것을 모른다고 하는 것, 그것이 참된 앎이다。",
|
||||
},
|
||||
{
|
||||
en: "Curiosity is the wick in the candle of learning.",
|
||||
zh: "好奇心是学习这支蜡烛的灯芯。",
|
||||
zh_TW: "好奇心是學習這支蠟燭的燈芯。",
|
||||
ja: "好奇心は、学習というロウソクの芯である。",
|
||||
ko: "호기심은 배움이라는 촛불의 심지이다。",
|
||||
},
|
||||
{
|
||||
en: "It is the mark of an educated mind to be able to entertain a thought without accepting it.",
|
||||
zh: "能够容纳一种思想而不同意它,这是一个受过教育的头脑的标志。",
|
||||
zh_TW: "能夠容納一種思想而不同意它,這是一個受過教育的頭腦的標誌。",
|
||||
ja: "ある考えを受け入れずに、その考えを持ち続けることができるのが、教育ある精神の証である。",
|
||||
ko: "어떤 생각을 받아들이지 않고도 그 생각을 해볼 수 있는 것이 교육받은 마음의 특징이다。",
|
||||
},
|
||||
{
|
||||
en: "Never stop questioning.",
|
||||
zh: "永远不要停止提问。",
|
||||
zh_TW: "永遠不要停止提問。",
|
||||
ja: "疑問を持つことを決してやめるな。",
|
||||
ko: "질문하는 것을 절대 멈추지 마라。",
|
||||
},
|
||||
{
|
||||
en: "The man who asks a question is a fool for a minute, the man who does not ask is a fool for life.",
|
||||
zh: "问问题的人,只傻一分钟;不问的人,傻一生。",
|
||||
zh_TW: "問問題的人,只傻一分鐘;不問的人,傻一生。",
|
||||
ja: "問う者は一時の恥、問わぬ者は一生の恥。",
|
||||
ko: "질문하는 사람은 1분 동안 바보가 되지만, 질문하지 않는 사람은 평생 바보가 된다。",
|
||||
},
|
||||
{
|
||||
en: "Wisdom is not a product of schooling but of the lifelong attempt to acquire it.",
|
||||
zh: "智慧不是学校教育的产物,而是终生努力获得的产物。",
|
||||
zh_TW: "智慧不是學校教育的產物,而是終生努力獲得的產物。",
|
||||
ja: "知恵とは学校教育の産物ではなく、生涯をかけて獲得しようと試みることで得られるものである。",
|
||||
ko: "지혜는 학교 교육의 산물이 아니라, 평생에 걸쳐 그것을 얻으려는 노력의 산물이다。",
|
||||
},
|
||||
{
|
||||
en: "The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.",
|
||||
zh: "知识最大的敌人不是无知,而是自以为拥有知识的幻觉。",
|
||||
zh_TW: "知識最大的敵人不是無知,而是自以為擁有知識的幻覺。",
|
||||
ja: "知識の最大の敵は無知ではなく、知っているという幻想である。",
|
||||
ko: "지식의 가장 큰 적은 무지가 아니라, 안다는 착각이다。",
|
||||
},
|
||||
{
|
||||
en: "True wisdom comes to each of us when we realize how little we understand about life, ourselves, and the world around us.",
|
||||
zh: "当我们认识到自己对生命、对自身、对周围世界了解得多么少时,真正的智慧才会降临到我们每个人身上。",
|
||||
zh_TW:
|
||||
"當我們認識到自己對生命、對自身、對周圍世界了解得多麼少時,真正的智慧才會降臨到我們每個人身上。",
|
||||
ja: "真の知恵は、我々が人生や自分自身、そして我々を取り巻く世界について、いかにわずかしか理解していないかを悟ったときに訪れる。",
|
||||
ko: "진정한 지혜는 우리가 삶과 우리 자신, 그리고 우리를 둘러싼 세계에 대해 얼마나 아는 것이 없는지를 깨달을 때 찾아온다。",
|
||||
},
|
||||
{
|
||||
en: "Beware of false knowledge; it is more dangerous than ignorance.",
|
||||
zh: "谨防虚假的知识;它比无知更危险。",
|
||||
zh_TW: "謹防虛假的知識;它比無知更危險。",
|
||||
ja: "偽りの知識に用心せよ。それは無知よりも危険である。",
|
||||
ko: "거짓된 지식을 경계하라. 그것은 무지보다 더 위험하다。",
|
||||
},
|
||||
{
|
||||
en: "What does not kill me makes me stronger.",
|
||||
zh: "杀不死我的,使我更强大。",
|
||||
zh_TW: "殺不死我的,使我更強大。",
|
||||
ja: "私を殺さないものは、私をより強くする。",
|
||||
ko: "나를 죽이지 못하는 것은 나를 더 강하게 만든다。",
|
||||
},
|
||||
{
|
||||
en: "The only constant in life is change.",
|
||||
zh: "生活中唯一不变的就是变化。",
|
||||
zh_TW: "生活中唯一不變的就是變化。",
|
||||
ja: "人生で唯一変わらないものは、変化そのものである。",
|
||||
ko: "삶에서 유일하게 변하지 않는 것은 변화뿐이다。",
|
||||
},
|
||||
{
|
||||
en: "If you are going through hell, keep going.",
|
||||
zh: "如果你正在经历地狱,那就继续走下去。",
|
||||
zh_TW: "如果你正在經歷地獄,那就繼續走下去。",
|
||||
ja: "地獄を経験しているなら、進み続けろ。",
|
||||
ko: "지옥을 겪고 있다면, 계속 나아가라。",
|
||||
},
|
||||
{
|
||||
en: "In the middle of difficulty lies opportunity.",
|
||||
zh: "机会蕴藏在困难之中。",
|
||||
zh_TW: "機會蘊藏在困難之中。",
|
||||
ja: "困難の真っ只中に、好機がある。",
|
||||
ko: "어려움의 한가운데에 기회가 있다。",
|
||||
},
|
||||
{
|
||||
en: "It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change.",
|
||||
zh: "存活下来的物种不是最强壮的,也不是最聪明的,而是最能适应变化的。",
|
||||
zh_TW: "存活下來的物種不是最强壯的,也不是最聰明的,而是最能適應變化的。",
|
||||
ja: "生き残る種とは、最も強いものでも、最も知的なものでもない。最も変化に対応できるものである。",
|
||||
ko: "살아남는 종은 가장 강한 종도, 가장 지능이 높은 종도 아니다. 변화에 가장 잘 적응하는 종이다。",
|
||||
},
|
||||
{
|
||||
en: "We must become the change we wish to see in the world.",
|
||||
zh: "我们必须成为我们希望在世界上看到的改变。",
|
||||
zh_TW: "我們必須成為我們希望在世界上看到的改變。",
|
||||
ja: "世界に変化を望むなら、まず自らがその変化となれ。",
|
||||
ko: "우리는 세상에서 보고 싶은 변화가 되어야 한다。",
|
||||
},
|
||||
{
|
||||
en: "A smooth sea never made a skilled sailor.",
|
||||
zh: "平静的大海练不出熟练的水手。",
|
||||
zh_TW: "平靜的大海練不出熟練的水手。",
|
||||
ja: "穏やかな海は、熟練した船乗りを育てない。",
|
||||
ko: "순탄한 바다는 노련한 뱃사공을 만들지 못한다。",
|
||||
},
|
||||
{
|
||||
en: "Obstacles don't block the path, they are the path.",
|
||||
zh: "障碍不是挡住了路,障碍本身就是路。",
|
||||
zh_TW: "障礙不是擋住了路,障礙本身就是路。",
|
||||
ja: "障害は道を塞ぐものではなく、道そのものである。",
|
||||
ko: "장애물은 길을 막는 것이 아니라, 그 자체가 길이다。",
|
||||
},
|
||||
{
|
||||
en: "Fall seven times, stand up eight.",
|
||||
zh: "七次跌倒,八次站起。",
|
||||
zh_TW: "七次跌倒,八次站起。",
|
||||
ja: "七転び八起き。",
|
||||
ko: "일곱 번 넘어져도, 여덟 번 일어선다。",
|
||||
},
|
||||
{
|
||||
en: "The art of life lies in a constant readjustment to our surroundings.",
|
||||
zh: "生活的艺术在于不断地调整自己以适应环境。",
|
||||
zh_TW: "生活的藝術在於不斷地調整自己以適應環境。",
|
||||
ja: "人生(じんせい)の芸術(げいじゅつ)は、我々(われわれ)の環境(かんきょう)に対(たい)する絶(た)え間(ま)ない再調整(さいちょうせい)にある。",
|
||||
ko: "삶의 기술은 우리를 둘러싼 환경에 끊임없이 재적응하는 데 있다。",
|
||||
},
|
||||
{
|
||||
en: "Adversity introduces a man to himself.",
|
||||
zh: "逆境使人认识自己。",
|
||||
zh_TW: "逆境使人認識自己。",
|
||||
ja: "逆境は、人に自分自身を教えてくれる。",
|
||||
ko: "역경은 사람에게 자기 자신을 소개한다。",
|
||||
},
|
||||
{
|
||||
en: "The wound is the place where the Light enters you.",
|
||||
zh: "伤口是光进入你内心的入口。",
|
||||
zh_TW: "傷口是光進入你內心的入口。",
|
||||
ja: "傷口は、光があなたの中に入る場所だ。",
|
||||
ko: "상처는 빛이 당신에게 들어오는 곳이다。",
|
||||
},
|
||||
{
|
||||
en: "When we are no longer able to change a situation, we are challenged to change ourselves.",
|
||||
zh: "当我们无法改变现状时,我们就需要改变自己。",
|
||||
zh_TW: "當我們無法改變現狀時,我們就需要改變自己。",
|
||||
ja: "状況を変えることができなくなったとき、我々は自分自身を変えることを求められる。",
|
||||
ko: "상황을 더 이상 바꿀 수 없을 때, 우리는 자신을 바꿔야 하는 도전에 직면한다。",
|
||||
},
|
||||
{
|
||||
en: "Be the change you wish to see in the world.",
|
||||
zh: "成为你希望在世界上看到的改变。",
|
||||
zh_TW: "成為你希望在世界上看到的改變。",
|
||||
ja: "あなたが世界に見たいと願う変化に、あなた自身がなりなさい。",
|
||||
ko: "세상에서 보고 싶은 변화가 있다면, 당신 자신이 그 변화가 되어라。",
|
||||
},
|
||||
{
|
||||
en: "Do not pray for an easy life, pray for the strength to endure a difficult one.",
|
||||
zh: "不要祈祷生活安逸,要祈祷有力量去忍受艰难的生活。",
|
||||
zh_TW: "不要祈禱生活安逸,要祈禱有力量去忍受艱難的生活。",
|
||||
ja: "楽な人生を祈るな。困難な人生を耐え抜く強さを祈れ。",
|
||||
ko: "편안한 삶을 기도하지 말고, 어려운 삶을 견뎌낼 힘을 기도하라。",
|
||||
},
|
||||
{
|
||||
en: "A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty.",
|
||||
zh: "悲观者在每个机会中都看到困难;乐观者在每个困难中都看到机会。",
|
||||
zh_TW: "悲觀者在每個機會中都看到困難;樂觀者在每個困難中都看到機會。",
|
||||
ja: "悲観主義者はあらゆる好機の中に困難を見る。楽観主義者はあらゆる困難の中に好機を見る。",
|
||||
ko: "비관론자는 모든 기회에서 어려움을 보고, 낙관론자는 모든 어려움에서 기회를 본다。",
|
||||
},
|
||||
{
|
||||
en: "It's not what happens to you, but how you react to it that matters.",
|
||||
zh: "重要的不是发生在你身上的事,而是你如何应对它。",
|
||||
zh_TW: "重要的不是發生在你身上的事,而是你如何應對它。",
|
||||
ja: "あなたに何が起こるかではなく、それにどう反応するかが重要だ。",
|
||||
ko: "당신에게 무슨 일이 일어났는지가 중요한 것이 아니라, 당신이 그것에 어떻게 반응하는지가 중요하다。",
|
||||
},
|
||||
{
|
||||
en: "To love oneself is the beginning of a lifelong romance.",
|
||||
zh: "爱自己是终身浪漫的开始。",
|
||||
zh_TW: "愛自己是終身浪漫的開始。",
|
||||
ja: "自分自身を愛することは、一生続くロマンスの始まりだ。",
|
||||
ko: "자신을 사랑하는 것은 평생 지속되는 로맨스의 시작이다。",
|
||||
},
|
||||
{
|
||||
en: "Love is composed of a single soul inhabiting two bodies.",
|
||||
zh: "爱是栖息于两个身体中的同一个灵魂。",
|
||||
zh_TW: "愛是棲息於兩個身體中的同一個靈魂。",
|
||||
ja: "愛とは、二つの体に宿る一つの魂で構成されている。",
|
||||
ko: "사랑은 두 개의 몸에 깃든 하나의 영혼으로 이루어져 있다。",
|
||||
},
|
||||
{
|
||||
en: "Man is the measure of all things.",
|
||||
zh: "人是万物的尺度。",
|
||||
zh_TW: "人是萬物的尺度。",
|
||||
ja: "人間は万物の尺度である。",
|
||||
ko: "인간은 만물의 척도이다。",
|
||||
},
|
||||
{
|
||||
en: "The best and most beautiful things in this world cannot be seen or even heard, but must be felt with the heart.",
|
||||
zh: "世界上最好最美的东西是看不见也听不见的,必须用心去感受。",
|
||||
zh_TW: "世界上最好最美的東西是看不見也聽不見的,必須用心去感受。",
|
||||
ja: "この世で最も素晴らしく、最も美しいものは、目で見たり聞いたりすることはできない。心で感じなければならない。",
|
||||
ko: "이 세상에서 가장 좋고 가장 아름다운 것들은 보이거나 들리지 않는다. 오직 마음으로만 느껴야 한다。",
|
||||
},
|
||||
{
|
||||
en: "Where there is love there is life.",
|
||||
zh: "有爱的地方就有生命。",
|
||||
zh_TW: "有愛的地方就有生命。",
|
||||
ja: "愛があるところに人生がある。",
|
||||
ko: "사랑이 있는 곳에 삶이 있다。",
|
||||
},
|
||||
{
|
||||
en: "If you want to be loved, be lovable.",
|
||||
zh: "如果你想被爱,就要变得可爱。",
|
||||
zh_TW: "如果你想被愛,就要變得可愛。",
|
||||
ja: "愛されたいなら、愛らしくあれ。",
|
||||
ko: "사랑받고 싶다면, 사랑스러워져라。",
|
||||
},
|
||||
{
|
||||
en: "We are all in the gutter, but some of us are looking at the stars.",
|
||||
zh: "我们都身处沟渠,但仍有人仰望星空。",
|
||||
zh_TW: "我們都身處溝渠,但仍有人仰望星空。",
|
||||
ja: "我々はみな溝の中にいる。だが、そこから星を見上げている者もいるのだ。",
|
||||
ko: "우리는 모두 시궁창에 있지만, 우리 중 일부는 별을 바라보고 있다。",
|
||||
},
|
||||
{
|
||||
en: "The only thing we have to fear is fear itself.",
|
||||
zh: "我们唯一需要恐惧的就是恐惧本身。",
|
||||
zh_TW: "我們唯一需要恐懼的就是恐懼本身。",
|
||||
ja: "我々が恐れるべき唯一のものは、恐れそのものである。",
|
||||
ko: "우리가 두려워해야 할 유일한 것은 두려움 그 자체이다。",
|
||||
},
|
||||
{
|
||||
en: "Be kind, for everyone you meet is fighting a hard battle.",
|
||||
zh: "要友善,因为你遇到的每个人都在打一场艰苦的战斗。",
|
||||
zh_TW: "要友善,因為你遇到的每個人都在打一場艱苦的戰鬥。",
|
||||
ja: "親切にしなさい。あなたが出会う誰もが、困難な戦いを戦っているのだから。",
|
||||
ko: "친절하라. 당신이 만나는 모든 사람은 힘겨운 싸움을 하고 있기 때문이다。",
|
||||
},
|
||||
{
|
||||
en: "Man is born free, and everywhere he is in chains.",
|
||||
zh: "人生而自由,却无往不在枷锁之中。",
|
||||
zh_TW: "人生而自由,卻無往不在枷鎖之中。",
|
||||
ja: "人は生まれながらにして自由だが、いたるところで鎖につながれている。",
|
||||
ko: "인간은 자유롭게 태어났으나, 어디에서나 쇠사슬에 묶여 있다。",
|
||||
},
|
||||
{
|
||||
en: "We love the things we love for what they are.",
|
||||
zh: "我们爱我们所爱之物,只因它们本来的样子。",
|
||||
zh_TW: "我們愛我們所愛之物,只因它們本來的樣子。",
|
||||
ja: "我々が愛するものを愛するのは、それがそれであるからだ。",
|
||||
ko: "우리는 우리가 사랑하는 것들을 그 자체로 사랑한다。",
|
||||
},
|
||||
{
|
||||
en: "Darkness cannot drive out darkness; only light can do that. Hate cannot drive out hate; only love can do that.",
|
||||
zh: "黑暗无法驱逐黑暗,只有光明可以;仇恨无法驱逐仇恨,只有爱可以。",
|
||||
zh_TW: "黑暗無法驅逐黑暗,只有光明可以;仇恨無法驅逐仇恨,只有愛可以。",
|
||||
ja: "闇は闇を追い払うことはできない。光だけがそれを可能にする。憎しみは憎しみを追い払うことはできない。愛だけがそれを可能にする。",
|
||||
ko: "어둠은 어둠을 몰아낼 수 없다. 오직 빛만이 할 수 있다. 증오는 증오를 몰아낼 수 없다. 오직 사랑만이 할 수 있다。",
|
||||
},
|
||||
{
|
||||
en: "An eye for an eye only ends up making the whole world blind.",
|
||||
zh: "以眼还眼,只会让整个世界都盲目。",
|
||||
zh_TW: "以眼還眼,只會讓整個世界都盲目。",
|
||||
ja: "「目には目を」は、全世界を盲目にするだけだ。",
|
||||
ko: "'눈에는 눈'은 결국 온 세상을 눈멀게 할 뿐이다。",
|
||||
},
|
||||
{
|
||||
en: "Hell is other people.",
|
||||
zh: "他人即地狱。",
|
||||
zh_TW: "他人即地獄。",
|
||||
ja: "地獄とは、他人である。",
|
||||
ko: "타인은 지옥이다。",
|
||||
},
|
||||
{
|
||||
en: "You will not be punished for your anger, you will be punished by your anger.",
|
||||
zh: "你不会因为你的愤怒而受到惩罚,你会被你的愤怒所惩罚。",
|
||||
zh_TW: "你不會因為你的憤怒而受到懲罰,你會被你的憤怒所懲罰。",
|
||||
ja: "あなたは怒りのために罰せられるのではない。怒りによって罰せられるのだ。",
|
||||
ko: "당신은 당신의 분노 때문에 벌을 받는 것이 아니라, 당신의 분노에 의해 벌을 받을 것이다。",
|
||||
},
|
||||
{
|
||||
en: "To err is human, to forgive divine.",
|
||||
zh: "犯错是人性,宽恕是神性。",
|
||||
zh_TW: "犯錯是人性,寬恕是神性。",
|
||||
ja: "過つは人の常、許すは神の業。",
|
||||
ko: "실수하는 것은 인간이고, 용서하는 것은 신이다。",
|
||||
},
|
||||
{
|
||||
en: "Man is the only creature who refuses to be what he is.",
|
||||
zh: "人是唯一拒绝承认自己本质的生物。",
|
||||
zh_TW: "人是唯一拒絕承認自己本質的生物。",
|
||||
ja: "人間は、自分が何者であるかを拒否する唯一の生き物である。",
|
||||
ko: "인간은 자신이 무엇인지를 거부하는 유일한 생물이다。",
|
||||
},
|
||||
{
|
||||
en: "Beauty is in the eye of the beholder.",
|
||||
zh: "情人眼里出西施。",
|
||||
zh_TW: "情人眼裡出西施。",
|
||||
ja: "美は見る人の目の中にある。",
|
||||
ko: "아름다움은 보는 사람의 눈에 달려 있다。",
|
||||
},
|
||||
{
|
||||
en: "All that we see or seem is but a dream within a dream.",
|
||||
zh: "我们所见所感,皆如梦中之梦。",
|
||||
zh_TW: "我們所見所感,皆如夢中之夢。",
|
||||
ja: "我々が見たり感じたりするすべては、夢の中の夢にすぎない。",
|
||||
ko: "우리가 보거나 보이는 모든 것은 꿈속의 꿈일 뿐이다。",
|
||||
},
|
||||
{
|
||||
en: "Everything you can imagine is real.",
|
||||
zh: "你能想象的一切都是真实的。",
|
||||
zh_TW: "你能想像的一切都是真實的。",
|
||||
ja: "想像できることは、すべて現実なのだ。",
|
||||
ko: "당신이 상상할 수 있는 모든 것은 현실이다。",
|
||||
},
|
||||
{
|
||||
en: "The map is not the territory.",
|
||||
zh: "地图并非领土。",
|
||||
zh_TW: "地圖並非領土。",
|
||||
ja: "地図は領土ではない。",
|
||||
ko: "지도는 영토가 아니다。",
|
||||
},
|
||||
{
|
||||
en: "We don't see things as they are, we see them as we are.",
|
||||
zh: "我们看到的不是事物的原貌,而是我们自己的样子。",
|
||||
zh_TW: "我們看到的不是事物的原貌,而是我們自己的樣子。",
|
||||
ja: "我々は物事をあるがままに見ているのではない。我々があるがままに見ているのだ。",
|
||||
ko: "우리는 사물을 있는 그대로 보지 않고, 우리 자신(의 모습)대로 본다。",
|
||||
},
|
||||
{
|
||||
en: "There are two ways to be fooled. One is to believe what isn't true; the other is to refuse to believe what is true.",
|
||||
zh: "被愚弄有两种方式。一种是相信不真实的东西;另一种是拒绝相信真实的东西。",
|
||||
zh_TW:
|
||||
"被愚弄有兩種方式。一種是相信不真實的東西;另一種是拒絕相信真實的東西。",
|
||||
ja: "騙される方法は二つある。一つは真実でないことを信じること。もう一つは真実であることを信じようとしないことだ。",
|
||||
ko: "속는 방법에는 두 가지가 있다. 하나는 사실이 아닌 것을 믿는 것이고, 다른 하나는 사실인 것을 믿기를 거부하는 것이다。",
|
||||
},
|
||||
{
|
||||
en: "Simplicity is the ultimate sophistication.",
|
||||
zh: "简约是极致的复杂。",
|
||||
zh_TW: "簡約是極致的複雜。",
|
||||
ja: "シンプルさは、究極の洗練である。",
|
||||
ko: "단순함은 궁극의 정교함이다。",
|
||||
},
|
||||
{
|
||||
en: "The truth will set you free.",
|
||||
zh: "真相将使你自由。",
|
||||
zh_TW: "真相將使你自由。",
|
||||
ja: "真実は、あなたを自由にする。",
|
||||
ko: "진리가 너희를 자유롭게 하리라。",
|
||||
},
|
||||
{
|
||||
en: "Reality is merely an illusion, albeit a very persistent one.",
|
||||
zh: "现实只是一种幻觉,尽管是一种非常持久的幻觉。",
|
||||
zh_TW: "現實只是一種幻覺,儘管是一種非常持久的幻覺。",
|
||||
ja: "現実とは、非常に根強いただの幻想にすぎない。",
|
||||
ko: "현실은 단지 환상일 뿐이다. 비록 매우 집요한 환상이긴 하지만。",
|
||||
},
|
||||
{
|
||||
en: "What is rational is actual and what is actual is rational.",
|
||||
zh: "凡是合乎理性的东西都是现实的,凡是现实的东西都是合乎理性的。",
|
||||
zh_TW: "凡是合乎理性的東西都是現實的,凡是現實的東西都是合乎理性的。",
|
||||
ja: "理性的なものは現実的であり、現実的なものは理性的である。",
|
||||
ko: "이성적인 것은 현실적이고, 현실적인 것은 이성적이다。",
|
||||
},
|
||||
{
|
||||
en: "Truth is like the sun. You can shut it out for a time, but it ain't goin' away.",
|
||||
zh: "真相就像太阳。你可以暂时将它遮住,但它不会消失。",
|
||||
zh_TW: "真相就像太陽。你可以暫時將它遮住,但它不會消失。",
|
||||
ja: "真実は太陽のようなものだ。一時的に隠すことはできても、決してなくなりはしない。",
|
||||
ko: "진실은 태양과 같다. 잠시 가릴 수는 있지만, 사라지게 할 수는 없다。",
|
||||
},
|
||||
{
|
||||
en: "Everything we hear is an opinion, not a fact. Everything we see is a perspective, not the truth.",
|
||||
zh: "我们听到的一切都只是观点,而非事实。我们看到的一切都只是视角,而非真相。",
|
||||
zh_TW:
|
||||
"我們聽到的一切都只是觀點,而非事實。我們看到的一切都只是視角,而非真相。",
|
||||
ja: "我々が聞くことすべてが意見であり、事実ではない。我々が見ることすべてが視点であり、真実ではない。",
|
||||
ko: "우리가 듣는 모든 것은 의견이지, 사실이 아니다. 우리가 보는 모든 것은 관점이지, 진실이 아니다。",
|
||||
},
|
||||
{
|
||||
en: "There is no truth. There is only perception.",
|
||||
zh: "没有真相,只有认知。",
|
||||
zh_TW: "沒有真相,只有認知。",
|
||||
ja: "真実などない。ただ認識があるだけだ。",
|
||||
ko: "진실은 없다. 오직 인식만이 있을 뿐이다。",
|
||||
},
|
||||
{
|
||||
en: "If you look deep enough into anything, you will find mathematics.",
|
||||
zh: "如果你对任何事物看得足够深入,你都会发现数学。",
|
||||
zh_TW: "如果你對任何事物看得足夠深入,你都會發現數學。",
|
||||
ja: "何事も深く見つめれば、そこには数学がある。",
|
||||
ko: "무엇이든 충분히 깊이 들여다보면, 수학을 발견하게 될 것이다。",
|
||||
},
|
||||
{
|
||||
en: "The medium is the message.",
|
||||
zh: "媒介即信息。",
|
||||
zh_TW: "媒介即訊息。",
|
||||
ja: "メディアはメッセージである。",
|
||||
ko: "미디어는 메시지다。",
|
||||
},
|
||||
{
|
||||
en: "Nothing is true, everything is permitted.",
|
||||
zh: "没有什么是真实的,一切都被允许。",
|
||||
zh_TW: "沒有什麼是真實的,一切都被允許。",
|
||||
ja: "真実などない、すべては許されている。",
|
||||
ko: "진실은 없으며, 모든 것이 허용된다。",
|
||||
},
|
||||
{
|
||||
en: "We are what we believe we are.",
|
||||
zh: "我们相信自己是什么,我们就是什么。",
|
||||
zh_TW: "我們相信自己是什麼,我們就是什麼。",
|
||||
ja: "我々は、我々が信じる通りの人間である。",
|
||||
ko: "우리는 우리가 그렇다고 믿는 존재이다。",
|
||||
},
|
||||
{
|
||||
en: "Yesterday is history, tomorrow is a mystery, but today is a gift. That is why it is called the present.",
|
||||
zh: "昨天是历史,明天是谜团,但今天是礼物。这就是为什么它被称为‘现在’(Present)。",
|
||||
zh_TW:
|
||||
"昨天是歷史,明天是謎團,但今天是禮物。這就是為什麼它被稱為‘現在’(Present)。",
|
||||
ja: "昨日は歴史、明日はミステリー、しかし今日は贈り物だ。だからこそ、それは『プレゼント (現在)』と呼ばれる。",
|
||||
ko: "어제는 역사이고, 내일은 미스터리이며, 오늘은 선물이다. 그래서 오늘을 '선물(present)'이라고 부른다。",
|
||||
},
|
||||
{
|
||||
en: "Time is money.",
|
||||
zh: "时间就是金钱。",
|
||||
zh_TW: "時間就是金錢。",
|
||||
ja: "時は金なり。",
|
||||
ko: "시간은 돈이다。",
|
||||
},
|
||||
{
|
||||
en: "The only thing necessary for the triumph of evil is for good men to do nothing.",
|
||||
zh: "邪恶得逞的唯一条件是好人袖手旁观。",
|
||||
zh_TW: "邪惡得逞的唯一條件是好人袖手旁觀。",
|
||||
ja: "悪が勝利するために必要なのは、善人が何もしないことだけである。",
|
||||
ko: "악의 승리를 위해 필요한 유일한 것은 선한 사람들이 아무것도 하지 않는 것이다。",
|
||||
},
|
||||
{
|
||||
en: "Carpe diem.",
|
||||
zh: "活在当下。",
|
||||
zh_TW: "活在當下。",
|
||||
ja: "今を生きよ(カルペ・ディエム)。",
|
||||
ko: "현재를 즐겨라 (카르페 디엠)。",
|
||||
},
|
||||
{
|
||||
en: "Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment.",
|
||||
zh: "不要沉湎于过去,不要幻想未来,集中精神活在当下。",
|
||||
zh_TW: "不要沉湎於過去,不要幻想未來,集中精神活在當下。",
|
||||
ja: "過去に生きるな、未来を夢見るな、現在の瞬間に心を集中させよ。",
|
||||
ko: "과거에 머물지 말고, 미래를 꿈꾸지 말며, 현재 이 순간에 마음을 집중하라。",
|
||||
},
|
||||
{
|
||||
en: "The best time to plant a tree was 20 years ago. The second best time is now.",
|
||||
zh: "种树的最佳时机是20年前。其次是现在。",
|
||||
zh_TW: "種樹的最佳時機是20年前。其次是現在。",
|
||||
ja: "木を植えるのに最適な時期は20年前だった。二番目に最適な時期は、今だ。",
|
||||
ko: "나무를 심기에 가장 좋은 때는 20년 전이었다. 두 번째로 좋은 때는 바로 지금이다。",
|
||||
},
|
||||
{
|
||||
en: "Action speaks louder than words.",
|
||||
zh: "事实胜于雄辩。",
|
||||
zh_TW: "事實勝於雄辯。",
|
||||
ja: "行動は言葉よりも雄弁である。",
|
||||
ko: "말보다 행동이 더 중요하다。",
|
||||
},
|
||||
{
|
||||
en: "Honesty is the first chapter in the book of wisdom.",
|
||||
zh: "诚实是智慧之书的第一章。",
|
||||
zh_TW: "誠實是智慧之書的第一章。",
|
||||
ja: "誠実さは、知恵という本の第一章である。",
|
||||
ko: "정직은 지혜라는 책의 첫 장이다。",
|
||||
},
|
||||
{
|
||||
en: "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.",
|
||||
zh: "有两样东西是无限的:宇宙和人类的愚蠢;而且我不太确定宇宙是否无限。",
|
||||
zh_TW: "有兩樣東西是無限的:宇宙和人類的愚蠢;而且我不太確定宇宙是否無限。",
|
||||
ja: "無限なものは二つある。宇宙と人間の愚かさだ。ただ、宇宙については私にもよく分からない。",
|
||||
ko: "무한한 것은 두 가지뿐이다. 우주와 인간의 어리석음. 그런데 우주에 대해선 나도 확신이 없다。",
|
||||
},
|
||||
{
|
||||
en: "You cannot step twice into the same river.",
|
||||
zh: "人不能两次踏进同一条河流。",
|
||||
zh_TW: "人不能兩次踏進同一條河流。",
|
||||
ja: "同(おな)じ川(かわ)に二度(にど)入(はい)ることはできない。",
|
||||
ko: "같은 강물에 두 번 발을 담글 수 없다。",
|
||||
},
|
||||
{
|
||||
en: "The future belongs to those who believe in the beauty of their dreams.",
|
||||
zh: "未来属于那些相信梦想之美的人。",
|
||||
zh_TW: "未來屬於那些相信夢想之美的人。",
|
||||
ja: "未来は、自分の夢の美しさを信じる者のものである。",
|
||||
ko: "미래는 자신의 꿈의 아름다움을 믿는 사람들의 것이다。",
|
||||
},
|
||||
{
|
||||
en: "Procrastination is the thief of time.",
|
||||
zh: "拖延是时间的大敌。",
|
||||
zh_TW: "拖延是時間的大敵。",
|
||||
ja: "先延ばしは時間泥棒である。",
|
||||
ko: "미루는 습관은 시간 도둑이다。",
|
||||
},
|
||||
{
|
||||
en: "An investment in knowledge pays the best interest.",
|
||||
zh: "投资知识,收益最佳。",
|
||||
zh_TW: "投資知識,收益最佳。",
|
||||
ja: "知識への投資は、最良の利息を生む。",
|
||||
ko: "지식에 대한 투자는 최고의 이자를 지불한다。",
|
||||
},
|
||||
{
|
||||
en: "I have not failed. I've just found 10,000 ways that won't work.",
|
||||
zh: "我没有失败。我只是找到了一万种行不通的方法。",
|
||||
zh_TW: "我沒有失敗。我只是找到了一萬種行不通的方法。",
|
||||
ja: "私は失敗したことがない。ただ、うまくいかない1万通りの方法を見つけただけだ。",
|
||||
ko: "나는 실패하지 않았다. 단지 작동하지 않는 1만 가지 방법을 찾았을 뿐이다。",
|
||||
},
|
||||
{
|
||||
en: "That which is done, is done.",
|
||||
zh: "木已成舟。",
|
||||
zh_TW: "木已成舟。",
|
||||
ja: "なされたことは、なされたことだ。(覆水盆に返らず)",
|
||||
ko: "일어난 일은 일어난 일이다. (이미 엎질러진 물이다.)",
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ export const SHADOW_KEY = ">>>";
|
||||
export const DEFAULT_COLOR = "#209CEE"; // 默认高亮背景色/线条颜色
|
||||
|
||||
export const DEFAULT_TRANS_TAG = "font";
|
||||
// export const DEFAULT_SELECT_STYLE =
|
||||
// "-webkit-line-clamp: unset; max-height: none; height: auto;";
|
||||
export const DEFAULT_SELECT_STYLE =
|
||||
"-webkit-line-clamp: unset; max-height: none; height: auto;";
|
||||
|
||||
export const OPT_TIMING_PAGESCROLL = "mk_pagescroll"; // 滚动加载翻译
|
||||
export const OPT_TIMING_PAGEOPEN = "mk_pageopen"; // 直接翻译到底
|
||||
@@ -108,7 +108,7 @@ export const GLOBLA_RULE = {
|
||||
textExtStyle: "", // 译文附加样式
|
||||
termsStyle: "font-weight: bold;", // 专业术语样式
|
||||
highlightStyle: "color: red;", // 高亮词汇样式
|
||||
selectStyle: "", // 选择器节点样式
|
||||
selectStyle: DEFAULT_SELECT_STYLE, // 选择器节点样式
|
||||
parentStyle: "", // 选择器父节点样式
|
||||
grandStyle: "", // 选择器祖节点样式
|
||||
injectJs: "", // 注入JS
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { run } from "./common";
|
||||
|
||||
globalThis.__KISS_CONTEXT__ = "content";
|
||||
|
||||
run();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { apiBaiduTTS } from "../apis";
|
||||
import { kissLog } from "../libs/log";
|
||||
import { logger } from "../libs/log";
|
||||
import { fetchData } from "../libs/fetch";
|
||||
|
||||
/**
|
||||
* 声音播放hook
|
||||
@@ -12,50 +12,97 @@ export function useAudio(src) {
|
||||
const [error, setError] = useState(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
const [playing, setPlaying] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const onPlay = useCallback(() => {
|
||||
audioRef.current?.play();
|
||||
const onPlay = useCallback(async () => {
|
||||
if (!audioRef.current) return;
|
||||
try {
|
||||
await audioRef.current.play();
|
||||
} catch (err) {
|
||||
logger.info("Playback failed:", err);
|
||||
setPlaying(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const onPause = useCallback(() => {
|
||||
audioRef.current?.pause();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!src) {
|
||||
return;
|
||||
}
|
||||
const audio = new Audio(src);
|
||||
audio.addEventListener("error", (err) => setError(err));
|
||||
audio.addEventListener("canplaythrough", () => setReady(true));
|
||||
audio.addEventListener("play", () => setPlaying(true));
|
||||
audio.addEventListener("ended", () => setPlaying(false));
|
||||
if (!src) return;
|
||||
|
||||
let ignore = false;
|
||||
let objectUrl = null;
|
||||
|
||||
setReady(false);
|
||||
setError(null);
|
||||
setPlaying(false);
|
||||
setLoading(true);
|
||||
|
||||
const audio = new Audio();
|
||||
audioRef.current = audio;
|
||||
|
||||
const handleCanPlay = () => setReady(true);
|
||||
const handlePlay = () => setPlaying(true);
|
||||
const handlePause = () => setPlaying(false);
|
||||
const handleEnded = () => setPlaying(false);
|
||||
const handleError = (e) => {
|
||||
if (!ignore) {
|
||||
setError(audio.error || e);
|
||||
setReady(false);
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
audio.addEventListener("canplaythrough", handleCanPlay);
|
||||
audio.addEventListener("play", handlePlay);
|
||||
audio.addEventListener("pause", handlePause);
|
||||
audio.addEventListener("ended", handleEnded);
|
||||
audio.addEventListener("error", handleError);
|
||||
|
||||
const loadAudio = async () => {
|
||||
try {
|
||||
const data = await fetchData(src, {}, { expect: "audio" });
|
||||
if (ignore) return;
|
||||
|
||||
audio.src = data;
|
||||
|
||||
setLoading(false);
|
||||
} catch (err) {
|
||||
if (!ignore) {
|
||||
logger.info("Audio fetch failed:", err);
|
||||
setError(err);
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
loadAudio();
|
||||
|
||||
return () => {
|
||||
ignore = true;
|
||||
|
||||
audio.pause();
|
||||
audio.removeAttribute("src");
|
||||
|
||||
if (objectUrl) {
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
}
|
||||
|
||||
audio.removeEventListener("canplaythrough", handleCanPlay);
|
||||
audio.removeEventListener("play", handlePlay);
|
||||
audio.removeEventListener("pause", handlePause);
|
||||
audio.removeEventListener("ended", handleEnded);
|
||||
audio.removeEventListener("error", handleError);
|
||||
};
|
||||
}, [src]);
|
||||
|
||||
return {
|
||||
loading,
|
||||
error,
|
||||
ready,
|
||||
playing,
|
||||
onPlay,
|
||||
onPause,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取语音hook
|
||||
* @param {*} text
|
||||
* @param {*} lan
|
||||
* @param {*} spd
|
||||
* @returns
|
||||
*/
|
||||
export function useTextAudio(text, lan = "uk", spd = 3) {
|
||||
const [src, setSrc] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
setSrc(await apiBaiduTTS(text, lan, spd));
|
||||
} catch (err) {
|
||||
kissLog("baidu tts", err);
|
||||
}
|
||||
})();
|
||||
}, [text, lan, spd]);
|
||||
|
||||
return useAudio(src);
|
||||
}
|
||||
|
||||
@@ -25,17 +25,15 @@ const SettingContext = createContext({
|
||||
reloadSetting: () => {},
|
||||
});
|
||||
|
||||
export function SettingProvider({ children, isSettingPage }) {
|
||||
export function SettingProvider({ children, context }) {
|
||||
const isOptionsPage = useMemo(() => context === "options", [context]);
|
||||
|
||||
const {
|
||||
data: setting,
|
||||
isLoading,
|
||||
update,
|
||||
reload,
|
||||
} = useStorage(
|
||||
STOKEY_SETTING,
|
||||
DEFAULT_SETTING,
|
||||
isSettingPage ? KV_SETTING_KEY : ""
|
||||
);
|
||||
} = useStorage(STOKEY_SETTING, DEFAULT_SETTING, KV_SETTING_KEY);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof setting?.darkMode === "boolean") {
|
||||
@@ -47,7 +45,7 @@ export function SettingProvider({ children, isSettingPage }) {
|
||||
}, [setting?.darkMode, update]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSettingPage) return;
|
||||
if (!isOptionsPage) return;
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
@@ -59,7 +57,7 @@ export function SettingProvider({ children, isSettingPage }) {
|
||||
logger.error("Failed to fetch log level, using default.", error);
|
||||
}
|
||||
})();
|
||||
}, [isSettingPage, setting?.logLevel]);
|
||||
}, [isOptionsPage, setting?.logLevel]);
|
||||
|
||||
const updateSetting = useCallback(
|
||||
(objOrFn) => {
|
||||
@@ -81,28 +79,31 @@ export function SettingProvider({ children, isSettingPage }) {
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
context,
|
||||
setting,
|
||||
updateSetting,
|
||||
updateChild,
|
||||
reloadSetting: reload,
|
||||
}),
|
||||
[setting, updateSetting, updateChild, reload]
|
||||
[context, setting, updateSetting, updateChild, reload]
|
||||
);
|
||||
|
||||
if (isLoading) {
|
||||
return <Loading />;
|
||||
return isOptionsPage ? <Loading /> : null;
|
||||
}
|
||||
|
||||
if (!setting) {
|
||||
<center>
|
||||
<Alert severity="error" sx={{ maxWidth: 600, margin: "60px auto" }}>
|
||||
<p>数据加载出错,请刷新页面或卸载后重新安装。</p>
|
||||
<p>
|
||||
Data loading error, please refresh the page or uninstall and
|
||||
reinstall.
|
||||
</p>
|
||||
</Alert>
|
||||
</center>;
|
||||
return isOptionsPage ? (
|
||||
<center>
|
||||
<Alert severity="error" sx={{ maxWidth: 600, margin: "60px auto" }}>
|
||||
<p>数据加载出错,请刷新页面或卸载后重新安装。</p>
|
||||
<p>
|
||||
Data loading error, please refresh the page or uninstall and
|
||||
reinstall.
|
||||
</p>
|
||||
</Alert>
|
||||
</center>
|
||||
) : null;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,6 +3,7 @@ import { storage } from "../libs/storage";
|
||||
import { kissLog } from "../libs/log";
|
||||
import { syncData } from "../libs/sync";
|
||||
import { useDebouncedCallback } from "./DebouncedCallback";
|
||||
import { isOptions } from "../libs/browser";
|
||||
|
||||
/**
|
||||
* 用于将组件状态与 Storage 同步
|
||||
@@ -79,7 +80,7 @@ export function useStorage(key, defaultVal = null, syncKey = "") {
|
||||
});
|
||||
|
||||
// 触发远端同步
|
||||
if (syncKey) {
|
||||
if (syncKey && isOptions()) {
|
||||
debouncedSync(syncKey, data);
|
||||
}
|
||||
}, [key, syncKey, isLoading, data, debouncedSync]);
|
||||
|
||||
@@ -14,7 +14,30 @@ function _browser() {
|
||||
|
||||
export const browser = _browser();
|
||||
|
||||
export const isBg = () => globalThis?.ContextType === "BACKGROUND";
|
||||
export const getContext = () => {
|
||||
const context = globalThis.__KISS_CONTEXT__;
|
||||
if (context) return context;
|
||||
|
||||
// if (typeof window === "undefined" || typeof document === "undefined") {
|
||||
// return "background";
|
||||
// }
|
||||
|
||||
// const extensionOrigin = browser.runtime.getURL("");
|
||||
// if (!window.location.href.startsWith(extensionOrigin)) {
|
||||
// return "content";
|
||||
// }
|
||||
|
||||
// const pathname = window.location.pathname;
|
||||
// if (pathname.includes("popup")) return "popup";
|
||||
// if (pathname.includes("options")) return "options";
|
||||
// if (pathname.includes("sidepanel")) return "sidepanel";
|
||||
// if (pathname.includes("background")) return "background";
|
||||
|
||||
return "undefined";
|
||||
};
|
||||
|
||||
export const isBg = () => getContext() === "background";
|
||||
export const isOptions = () => getContext() === "options";
|
||||
|
||||
export const isBuiltinAIAvailable =
|
||||
"LanguageDetector" in globalThis && "Translator" in globalThis;
|
||||
|
||||
@@ -16,7 +16,7 @@ import { blobToBase64 } from "./utils";
|
||||
*/
|
||||
export const tryClearCaches = async () => {
|
||||
try {
|
||||
if (isExt && !isBg) {
|
||||
if (isExt && !isBg()) {
|
||||
await sendBgMsg(MSG_CLEAR_CACHES);
|
||||
} else {
|
||||
await caches.delete(CACHE_NAME);
|
||||
@@ -50,13 +50,13 @@ const newCacheReq = async (input, init) => {
|
||||
* @param {*} init
|
||||
* @returns
|
||||
*/
|
||||
export const getHttpCache = async ({ input, init }) => {
|
||||
export const getHttpCache = async ({ input, init, expect }) => {
|
||||
try {
|
||||
const request = await newCacheReq(input, init);
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
const response = await cache.match(request);
|
||||
if (response) {
|
||||
const res = await parseResponse(response);
|
||||
const res = await parseResponse(response, expect);
|
||||
return res;
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -99,7 +99,7 @@ export const putHttpCache = async ({
|
||||
* @param {*} res
|
||||
* @returns
|
||||
*/
|
||||
export const parseResponse = async (res) => {
|
||||
export const parseResponse = async (res, expect = null) => {
|
||||
if (!res) {
|
||||
throw new Error("Response object does not exist");
|
||||
}
|
||||
@@ -108,21 +108,45 @@ export const parseResponse = async (res) => {
|
||||
const msg = {
|
||||
url: res.url,
|
||||
status: res.status,
|
||||
statusText: res.statusText,
|
||||
};
|
||||
if (res.headers.get("Content-Type")?.includes("json")) {
|
||||
msg.response = await res.json();
|
||||
|
||||
try {
|
||||
const errorText = await res.clone().text();
|
||||
try {
|
||||
msg.response = JSON.parse(errorText);
|
||||
} catch {
|
||||
msg.response = errorText;
|
||||
}
|
||||
} catch (e) {
|
||||
msg.response = "Unable to read error body";
|
||||
}
|
||||
|
||||
throw new Error(JSON.stringify(msg));
|
||||
}
|
||||
|
||||
const contentType = res.headers.get("Content-Type");
|
||||
if (contentType?.includes("json")) {
|
||||
return res.json();
|
||||
} else if (contentType?.includes("audio")) {
|
||||
const contentType = res.headers.get("Content-Type") || "";
|
||||
if (expect === "blob") return res.blob();
|
||||
if (expect === "text") return res.text();
|
||||
if (expect === "json") return res.json();
|
||||
if (
|
||||
expect === "audio" ||
|
||||
contentType.includes("audio") ||
|
||||
contentType.includes("image") ||
|
||||
contentType.includes("video")
|
||||
) {
|
||||
const blob = await res.blob();
|
||||
return blobToBase64(blob);
|
||||
}
|
||||
return res.text();
|
||||
|
||||
const text = await res.text();
|
||||
if (!text) return null;
|
||||
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch (err) {
|
||||
return text;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -99,7 +99,7 @@ export const fetchPatcher = async (input, init = {}, opts) => {
|
||||
*/
|
||||
export const fetchHandle = async ({ input, init, opts }) => {
|
||||
const res = await fetchPatcher(input, init, opts);
|
||||
return parseResponse(res);
|
||||
return parseResponse(res, opts.expect);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ export const injectInlineJs = (code, id = "kiss-translator-inline-js") => {
|
||||
}
|
||||
|
||||
const el = document.createElement("script");
|
||||
el.setAttribute("data-source", "kiss-inject injectInlineJs");
|
||||
el.type = "text/javascript";
|
||||
el.id = id;
|
||||
el.textContent = trustedTypesHelper.createScript(code);
|
||||
@@ -19,6 +20,7 @@ export const injectInlineJsBg = (code, id = "kiss-translator-inline-js") => {
|
||||
}
|
||||
|
||||
const el = document.createElement("script");
|
||||
el.setAttribute("data-source", "kiss-inject injectInlineJsBg");
|
||||
el.type = "text/javascript";
|
||||
el.id = id;
|
||||
el.textContent = code;
|
||||
@@ -32,6 +34,7 @@ export const injectExternalJs = (src, id = "kiss-translator-external-js") => {
|
||||
}
|
||||
|
||||
const el = document.createElement("script");
|
||||
el.setAttribute("data-source", "kiss-inject injectExternalJs");
|
||||
el.type = "text/javascript";
|
||||
el.id = id;
|
||||
el.src = trustedTypesHelper.createScriptURL(src);
|
||||
|
||||
@@ -11,7 +11,10 @@ import { createLoadingSVG } from "./svg";
|
||||
import { logger } from "./log";
|
||||
|
||||
function isInputNode(node) {
|
||||
return node.nodeName === "INPUT" || node.nodeName === "TEXTAREA";
|
||||
return (
|
||||
node.nodeName?.toUpperCase() === "INPUT" ||
|
||||
node.nodeName?.toUpperCase() === "TEXTAREA"
|
||||
);
|
||||
}
|
||||
|
||||
function isEditAbleNode(node) {
|
||||
|
||||
@@ -61,14 +61,25 @@ export const shortcutRegister = (targetKeys = [], fn, target = document) => {
|
||||
if (targetKeys.length === 0) return () => {};
|
||||
|
||||
const targetKeySet = new Set(targetKeys);
|
||||
let hasInterference = false;
|
||||
const onKeyDown = (pressedKeys, event) => {
|
||||
if (isSameSet(targetKeySet, pressedKeys)) {
|
||||
// event.preventDefault(); // 阻止浏览器的默认行为
|
||||
// event.stopPropagation(); // 阻止事件继续(向父元素)冒泡
|
||||
fn();
|
||||
// if (isSameSet(targetKeySet, pressedKeys)) {
|
||||
// // event.preventDefault(); // 阻止浏览器的默认行为
|
||||
// // event.stopPropagation(); // 阻止事件继续(向父元素)冒泡
|
||||
// fn();
|
||||
// }
|
||||
if (!targetKeySet.has(event.code)) {
|
||||
hasInterference = true;
|
||||
}
|
||||
};
|
||||
const onKeyUp = (pressedKeys, event) => {
|
||||
if (isSameSet(targetKeySet, pressedKeys) && !hasInterference) {
|
||||
fn();
|
||||
}
|
||||
if (pressedKeys.size === 1) {
|
||||
hasInterference = false;
|
||||
}
|
||||
};
|
||||
const onKeyUp = () => {};
|
||||
|
||||
return shortcutListener(onKeyDown, onKeyUp, target);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
APP_UPNAME,
|
||||
APP_LCNAME,
|
||||
APP_CONSTS,
|
||||
OPT_STYLE_FUZZY,
|
||||
@@ -153,7 +152,7 @@ export class Translator {
|
||||
|
||||
// 译文相关class
|
||||
static KISS_CLASS = {
|
||||
warpper: `${APP_LCNAME}-wrapper notranslate`,
|
||||
warpper: `${APP_LCNAME}-wrapper`,
|
||||
inner: `${APP_LCNAME}-inner`,
|
||||
term: `${APP_LCNAME}-term`,
|
||||
br: `${APP_LCNAME}-br`,
|
||||
@@ -224,8 +223,8 @@ export class Translator {
|
||||
static isBlockNode(el) {
|
||||
if (!Translator.isElementOrFragment(el)) return false;
|
||||
|
||||
if (Translator.TAGS.INLINE.has(el.nodeName)) return false;
|
||||
if (Translator.TAGS.BLOCK.has(el.nodeName)) return true;
|
||||
if (Translator.TAGS.INLINE.has(el.nodeName?.toUpperCase())) return false;
|
||||
if (Translator.TAGS.BLOCK.has(el.nodeName?.toUpperCase())) return true;
|
||||
if (el.attributes?.display?.value?.includes("inline")) return false;
|
||||
|
||||
if (Translator.displayCache.has(el)) {
|
||||
@@ -265,7 +264,7 @@ export class Translator {
|
||||
}
|
||||
|
||||
// 内置忽略元素
|
||||
static KISS_IGNORE_SELECTOR = `${APP_LCNAME}, .kiss-caption-container, .kiss-subtitle-controls
|
||||
static KISS_IGNORE_SELECTOR = `.${Translator.KISS_CLASS.warpper}, .kiss-caption-container, .kiss-subtitle-controls
|
||||
#${APP_CONSTS.fabID}, .${APP_CONSTS.fabID}_warpper,
|
||||
#${APP_CONSTS.boxID}, .${APP_CONSTS.boxID}_warpper,
|
||||
#${APP_CONSTS.popupID}, .${APP_CONSTS.popupID}_warpper`;
|
||||
@@ -288,7 +287,7 @@ export class Translator {
|
||||
#combinedTermsRegex; // 专业术语正则表达式
|
||||
#combinedSkipsRegex; // 跳过文本正则表达式
|
||||
#placeholderRegex; // 恢复htnml正则表达式
|
||||
#translationTagName = APP_UPNAME; // 翻译容器的标签名
|
||||
#translationTagName = APP_LCNAME; // 翻译容器的标签名
|
||||
#eventName = ""; // 通信事件名称
|
||||
#docInfo = {}; // 网页信息
|
||||
#glossary = {}; // AI词典
|
||||
@@ -602,7 +601,8 @@ export class Translator {
|
||||
for (const mutation of mutations) {
|
||||
if (
|
||||
this.#skipMoNodes.has(mutation.target) ||
|
||||
mutation.nextSibling?.tagName === this.#translationTagName
|
||||
mutation.nextSibling?.tagName?.toLowerCase() ===
|
||||
this.#translationTagName
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@@ -620,7 +620,7 @@ export class Translator {
|
||||
mutation.addedNodes.forEach((node) => {
|
||||
if (
|
||||
this.#skipMoNodes.has(node) ||
|
||||
node.nodeName === this.#translationTagName
|
||||
node.nodeName?.toLowerCase() === this.#translationTagName
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -1056,7 +1056,10 @@ export class Translator {
|
||||
textLength += node.textContent.length;
|
||||
|
||||
const isSentenceEnd = sentenceEndRegexForTest.test(node.textContent);
|
||||
if (!isSentenceEnd || node.nextSibling?.nodeName === "BR") {
|
||||
if (
|
||||
!isSentenceEnd ||
|
||||
node.nextSibling?.nodeName?.toUpperCase() === "BR"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1109,9 +1112,9 @@ export class Translator {
|
||||
if (node.matches(this.#rule.keepSelector)) return false;
|
||||
|
||||
if (
|
||||
Translator.TAGS.BREAK_LINE.has(node.nodeName) ||
|
||||
Translator.TAGS.BREAK_LINE.has(node.nodeName?.toUpperCase()) ||
|
||||
node.matches?.(this.#ignoreSelector) ||
|
||||
node.nodeName === this.#translationTagName
|
||||
node.nodeName?.toLowerCase() === this.#translationTagName
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@@ -1194,11 +1197,10 @@ export class Translator {
|
||||
nodes,
|
||||
termsStyle
|
||||
);
|
||||
// console.log("processedString", processedString);
|
||||
if (this.#isInvalidText(processedString)) return;
|
||||
|
||||
const wrapper = document.createElement(this.#translationTagName);
|
||||
wrapper.className = Translator.KISS_CLASS.warpper;
|
||||
wrapper.className = `${Translator.KISS_CLASS.warpper} notranslate`;
|
||||
|
||||
if (processedString.length > newlineLength) {
|
||||
const br = document.createElement("br");
|
||||
@@ -1443,7 +1445,9 @@ export class Translator {
|
||||
|
||||
// 查找指定节点下所有译文节点
|
||||
#findTranslationWrappers(parentNode) {
|
||||
return parentNode.querySelectorAll(`:scope > ${APP_LCNAME}`);
|
||||
return parentNode.querySelectorAll(
|
||||
`:scope > .${Translator.KISS_CLASS.warpper}`
|
||||
);
|
||||
}
|
||||
|
||||
// 清理所有插入的译文dom
|
||||
@@ -1454,7 +1458,7 @@ export class Translator {
|
||||
// 清理节点下面所有译文dom
|
||||
#cleanupAllTranslations(root) {
|
||||
root
|
||||
.querySelectorAll(APP_LCNAME)
|
||||
.querySelectorAll(`.${Translator.KISS_CLASS.warpper}`)
|
||||
.forEach((el) => this.#removeTranslationElement(el));
|
||||
}
|
||||
|
||||
|
||||
@@ -252,6 +252,8 @@ export default class TranslatorManager {
|
||||
sendIframeMsg(action, args);
|
||||
}
|
||||
|
||||
logger.debug("process action:", action, args);
|
||||
|
||||
switch (action) {
|
||||
case MSG_TRANS_TOGGLE:
|
||||
this._translator.toggle();
|
||||
|
||||
@@ -2,6 +2,8 @@ import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import Options from "./views/Options";
|
||||
|
||||
globalThis.__KISS_CONTEXT__ = "options";
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById("root"));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
|
||||
@@ -4,10 +4,12 @@ import { SettingProvider } from "./hooks/Setting";
|
||||
import ThemeProvider from "./hooks/Theme";
|
||||
import Popup from "./views/Popup";
|
||||
|
||||
globalThis.__KISS_CONTEXT__ = "popup";
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById("root"));
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<SettingProvider>
|
||||
<SettingProvider context="popup">
|
||||
<ThemeProvider>
|
||||
<Popup />
|
||||
</ThemeProvider>
|
||||
|
||||
@@ -45,7 +45,7 @@ export default function ContentFab({
|
||||
);
|
||||
|
||||
return (
|
||||
<SettingProvider>
|
||||
<SettingProvider context="fab">
|
||||
<ThemeProvider>
|
||||
<Draggable
|
||||
key="fab"
|
||||
|
||||
@@ -70,7 +70,7 @@ export default function Action({ translator, processActions }) {
|
||||
}, [windowSize]);
|
||||
|
||||
return (
|
||||
<SettingProvider>
|
||||
<SettingProvider context="contentPopup">
|
||||
<ThemeProvider>
|
||||
{showPopup && (
|
||||
<Draggable
|
||||
|
||||
@@ -76,7 +76,7 @@ function StyleFields({ customStyle, deleteStyle, updateStyle, isBuiltin }) {
|
||||
if (uiLang === "en") {
|
||||
return [q.zh, q.en];
|
||||
}
|
||||
return [q.en, q.zh];
|
||||
return [q.en, q[uiLang]];
|
||||
}, [uiLang]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -99,7 +99,7 @@ export default function Options() {
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingProvider isSettingPage={true}>
|
||||
<SettingProvider context="options">
|
||||
<ThemeProvider>
|
||||
<AlertProvider>
|
||||
<ConfirmProvider>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import VolumeUpIcon from "@mui/icons-material/VolumeUp";
|
||||
import { useAudio } from "../../hooks/Audio";
|
||||
import queryString from "query-string";
|
||||
|
||||
export default function AudioBtn({ src }) {
|
||||
export function AudioBtn({ src }) {
|
||||
const { error, ready, playing, onPlay } = useAudio(src);
|
||||
|
||||
if (error || !ready) {
|
||||
@@ -27,3 +28,10 @@ export default function AudioBtn({ src }) {
|
||||
</IconButton>
|
||||
);
|
||||
}
|
||||
|
||||
export function BaiduAudioBtn({ text, lan = "uk", spd = 3 }) {
|
||||
if (!text) return null;
|
||||
|
||||
const src = `https://fanyi.baidu.com/gettts?${queryString.stringify({ lan, text, spd })}`;
|
||||
return <AudioBtn src={src} />;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Typography from "@mui/material/Typography";
|
||||
import AudioBtn from "./AudioBtn";
|
||||
import { AudioBtn, BaiduAudioBtn } from "./AudioBtn";
|
||||
import { OPT_DICT_BING, OPT_DICT_YOUDAO } from "../../config";
|
||||
import { apiMicrosoftDict, apiYoudaoDict } from "../../apis";
|
||||
|
||||
@@ -48,12 +48,14 @@ export const dictHandlers = {
|
||||
style={{ display: "inline-block", paddingRight: "1em" }}
|
||||
>
|
||||
<Typography component="span">{`UK [${data?.ec?.word?.ukphone}]`}</Typography>
|
||||
<BaiduAudioBtn text={data?.ec?.word?.["return-phrase"]} lan="uk" />
|
||||
</Typography>
|
||||
<Typography
|
||||
component="div"
|
||||
style={{ display: "inline-block", paddingRight: "1em" }}
|
||||
>
|
||||
<Typography component="span">{`US [${data?.ec?.word?.usphone}]`}</Typography>
|
||||
<BaiduAudioBtn text={data?.ec?.word?.["return-phrase"]} lan="en" />
|
||||
</Typography>
|
||||
</Typography>
|
||||
),
|
||||
|
||||
@@ -141,7 +141,7 @@ export default function TranBox({
|
||||
const [mouseHover, setMouseHover] = useState(false);
|
||||
// todo: 这里的 SettingProvider 不应和 background 的共用
|
||||
return (
|
||||
<SettingProvider>
|
||||
<SettingProvider context="tranbox">
|
||||
<ThemeProvider styles={extStyles}>
|
||||
{showBox && (
|
||||
<DraggableResizable
|
||||
|
||||
@@ -133,7 +133,7 @@ export default function Slection({
|
||||
|
||||
useEffect(() => {
|
||||
async function handleMouseup(e) {
|
||||
e.stopPropagation();
|
||||
// e.stopPropagation();
|
||||
await sleep(200);
|
||||
|
||||
const selection = window.getSelection();
|
||||
|
||||
Reference in New Issue
Block a user