Add Chinese-English translation functionality during typing.
This commit is contained in:
1 parent
14c5467fc6
commit
96040385bc
11 files changed
+50
-8
No files matched your search
@@ -184,6 +184,7 @@
|
||||
background: #2d2d2d; border: 1px solid #9b9b9b2e; border-radius: 6px; padding: 1px 0; }
|
||||
.context-menu-parent:hover > .context-submenu { display: block; }
|
||||
.context-menu-separator { height: 1px; margin: 3px 5px; background: #ffffff20; }
|
||||
.cand-translation { margin-left: 0.65em; font-size: 0.78em; opacity: 0.62; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -200,7 +201,9 @@
|
||||
const contentEl = candElement.querySelector('.cand-content');
|
||||
if (!contentEl) return false;
|
||||
|
||||
let text = contentEl.textContent.trim();
|
||||
const candidateOnly = contentEl.cloneNode(true);
|
||||
candidateOnly.querySelectorAll('.cand-translation').forEach((node) => node.remove());
|
||||
let text = candidateOnly.textContent.trim();
|
||||
|
||||
// 去掉括号里的编码,例如:你们(rR) → 你们
|
||||
text = text.replace(/\(.*?\)$/, '').trim();
|
||||
|
||||
@@ -206,6 +206,7 @@
|
||||
.context-submenu { background: #23272c; border-color: #3a4047; border-radius: 3px; }
|
||||
.context-menu-item { color: #c7cdd5; border-radius: 2px; }
|
||||
.context-menu-item:hover { background: #30353b; }
|
||||
.cand-translation { margin-left: 0.65em; font-size: 0.78em; opacity: 0.62; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -222,7 +223,9 @@
|
||||
const contentEl = candElement.querySelector('.cand-content');
|
||||
if (!contentEl) return false;
|
||||
|
||||
let text = contentEl.textContent.trim();
|
||||
const candidateOnly = contentEl.cloneNode(true);
|
||||
candidateOnly.querySelectorAll('.cand-translation').forEach((node) => node.remove());
|
||||
let text = candidateOnly.textContent.trim();
|
||||
|
||||
// 去掉括号里的编码,例如:你们(rR) → 你们
|
||||
text = text.replace(/\(.*?\)$/, '').trim();
|
||||
|
||||
@@ -206,6 +206,7 @@
|
||||
.context-submenu { background: #ffffff; border-color: #dfe3e8; border-radius: 3px; }
|
||||
.context-menu-item { color: #374151; border-radius: 2px; }
|
||||
.context-menu-item:hover { background: #f1f3f5; }
|
||||
.cand-translation { margin-left: 0.65em; font-size: 0.78em; opacity: 0.62; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -222,7 +223,9 @@
|
||||
const contentEl = candElement.querySelector('.cand-content');
|
||||
if (!contentEl) return false;
|
||||
|
||||
let text = contentEl.textContent.trim();
|
||||
const candidateOnly = contentEl.cloneNode(true);
|
||||
candidateOnly.querySelectorAll('.cand-translation').forEach((node) => node.remove());
|
||||
let text = candidateOnly.textContent.trim();
|
||||
|
||||
// 去掉括号里的编码,例如:你们(rR) → 你们
|
||||
text = text.replace(/\(.*?\)$/, '').trim();
|
||||
|
||||
@@ -184,6 +184,7 @@
|
||||
background: #fff; border: 1px solid rgba(0,0,0,.12); border-radius: 6px; padding: 1px 0; }
|
||||
.context-menu-parent:hover > .context-submenu { display: block; }
|
||||
.context-menu-separator { height: 1px; margin: 3px 5px; background: #00000020; }
|
||||
.cand-translation { margin-left: 0.65em; font-size: 0.78em; opacity: 0.62; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -200,7 +201,9 @@
|
||||
const contentEl = candElement.querySelector('.cand-content');
|
||||
if (!contentEl) return false;
|
||||
|
||||
let text = contentEl.textContent.trim();
|
||||
const candidateOnly = contentEl.cloneNode(true);
|
||||
candidateOnly.querySelectorAll('.cand-translation').forEach((node) => node.remove());
|
||||
let text = candidateOnly.textContent.trim();
|
||||
|
||||
// 去掉括号里的编码,例如:你们(rR) → 你们
|
||||
text = text.replace(/\(.*?\)$/, '').trim();
|
||||
|
||||
@@ -209,6 +209,7 @@
|
||||
.context-submenu { background: #1f1f1f; border-color: #343434; }
|
||||
.context-menu-item { color: #d0d0d0; }
|
||||
.context-menu-item:hover { background: #2a2a2a; }
|
||||
.cand-translation { margin-left: 0.65em; font-size: 0.78em; opacity: 0.62; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -225,7 +226,9 @@
|
||||
const contentEl = candElement.querySelector('.cand-content');
|
||||
if (!contentEl) return false;
|
||||
|
||||
let text = contentEl.textContent.trim();
|
||||
const candidateOnly = contentEl.cloneNode(true);
|
||||
candidateOnly.querySelectorAll('.cand-translation').forEach((node) => node.remove());
|
||||
let text = candidateOnly.textContent.trim();
|
||||
|
||||
// 去掉括号里的编码,例如:你们(rR) → 你们
|
||||
text = text.replace(/\(.*?\)$/, '').trim();
|
||||
|
||||
@@ -204,6 +204,7 @@
|
||||
.context-submenu { background: #ffffff; border-color: #d9d9d9; }
|
||||
.context-menu-item { color: #333333; }
|
||||
.context-menu-item:hover { background: #eeeeee; }
|
||||
.cand-translation { margin-left: 0.65em; font-size: 0.78em; opacity: 0.62; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -220,7 +221,9 @@
|
||||
const contentEl = candElement.querySelector('.cand-content');
|
||||
if (!contentEl) return false;
|
||||
|
||||
let text = contentEl.textContent.trim();
|
||||
const candidateOnly = contentEl.cloneNode(true);
|
||||
candidateOnly.querySelectorAll('.cand-translation').forEach((node) => node.remove());
|
||||
let text = candidateOnly.textContent.trim();
|
||||
|
||||
// 去掉括号里的编码,例如:你们(rR) → 你们
|
||||
text = text.replace(/\(.*?\)$/, '').trim();
|
||||
|
||||
@@ -251,6 +251,7 @@
|
||||
.context-submenu { background: #343635; border-color: #454845; }
|
||||
.context-menu-item { color: #e0e2df; }
|
||||
.context-menu-item:hover { background: #414441; }
|
||||
.cand-translation { margin-left: 0.65em; font-size: 0.78em; opacity: 0.62; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -267,7 +268,9 @@
|
||||
const contentEl = candElement.querySelector('.cand-content');
|
||||
if (!contentEl) return false;
|
||||
|
||||
let text = contentEl.textContent.trim();
|
||||
const candidateOnly = contentEl.cloneNode(true);
|
||||
candidateOnly.querySelectorAll('.cand-translation').forEach((node) => node.remove());
|
||||
let text = candidateOnly.textContent.trim();
|
||||
|
||||
// 去掉括号里的编码,例如:你们(rR) → 你们
|
||||
text = text.replace(/\(.*?\)$/, '').trim();
|
||||
|
||||
@@ -248,6 +248,7 @@
|
||||
.context-submenu { background: #fbfcfa; border-color: #d8ded9; }
|
||||
.context-menu-item { color: #343936; }
|
||||
.context-menu-item:hover { background: #e9eeea; }
|
||||
.cand-translation { margin-left: 0.65em; font-size: 0.78em; opacity: 0.62; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -264,7 +265,9 @@
|
||||
const contentEl = candElement.querySelector('.cand-content');
|
||||
if (!contentEl) return false;
|
||||
|
||||
let text = contentEl.textContent.trim();
|
||||
const candidateOnly = contentEl.cloneNode(true);
|
||||
candidateOnly.querySelectorAll('.cand-translation').forEach((node) => node.remove());
|
||||
let text = candidateOnly.textContent.trim();
|
||||
|
||||
// 去掉括号里的编码,例如:你们(rR) → 你们
|
||||
text = text.replace(/\(.*?\)$/, '').trim();
|
||||
|
||||
@@ -119,6 +119,9 @@ export function setupConfigSync(): void {
|
||||
payload.data?.general?.cn_en_mixed_input,
|
||||
payload.data?.general?.cn_en_mixed_input_min_chars
|
||||
);
|
||||
if (typeof payload.data?.general?.candidate_translations === 'boolean') {
|
||||
applyToggleState('candidateTranslationsToggleBtn', payload.data.general.candidate_translations);
|
||||
}
|
||||
if (typeof payload.data?.general?.emoji_mixed_input === 'boolean') {
|
||||
applyToggleState('emojiMixedInputToggleBtn', payload.data.general.emoji_mixed_input);
|
||||
}
|
||||
|
||||
@@ -96,6 +96,9 @@ export function setupInput(): void {
|
||||
syncZhEnMixedInputOptionsEnabled(active);
|
||||
updateConfig('general.cn_en_mixed_input', active);
|
||||
});
|
||||
setupToggleButton('candidateTranslationsToggleBtn', (active) => {
|
||||
updateConfig('general.candidate_translations', active);
|
||||
});
|
||||
setupDropdownMenu(
|
||||
'zhEnTriggerLengthBtn',
|
||||
'zhEnTriggerLengthMenu',
|
||||
|
||||
@@ -80,6 +80,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div>
|
||||
<div class="section-title">候选词翻译</div>
|
||||
<div class="input-setting-description">仅在竖排候选窗口中显示中英互译,每项最多两个简短释义</div>
|
||||
</div>
|
||||
<div class="ftb-toggle-btn active" id="candidateTranslationsToggleBtn" role="switch" aria-checked="true" tabindex="0">
|
||||
<div class="ftb-toggle-knob"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div>
|
||||
|
||||
Reference in new issue
Block a user