magpie-select-translate 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -3
- package/bin/helper.exe +0 -0
- package/index.mjs +12 -6
- package/package.json +11 -6
- package/page/index.html +6 -6
package/README.md
CHANGED
|
@@ -38,17 +38,20 @@ Ctrl+C 在这些程序里有副作用,命中时只提示「该应用不支持
|
|
|
38
38
|
| 键 | 说明 |
|
|
39
39
|
|---|---|
|
|
40
40
|
| `port` | helper 本地端口,默认 3477 |
|
|
41
|
-
| `hotkey` | 全局热键,默认 `Alt+D
|
|
41
|
+
| `hotkey` | 全局热键,默认 `Alt+D` |
|
|
42
42
|
| `model` | 模型 id,留空用网关 `/v1/models` 的第一个 |
|
|
43
43
|
| `target` | `auto` / `zh` / `en` |
|
|
44
|
-
| `
|
|
44
|
+
| `glossary` | 术语表正文,每行 `原文=译文` |
|
|
45
45
|
|
|
46
46
|
设置页在沙箱里没有网络(`connect-src 'none'`),所以它只读写 `magpie.options`;
|
|
47
|
+
插件在拉起 helper 时把这几项转成命令行参数,helper 落地成自己的 `settings.json`。
|
|
48
|
+
改完要重启 helper(结束 `magpie-translate-helper.exe`,或重新加载插件)才生效。
|
|
47
49
|
翻译状态请看浮窗本身。
|
|
48
50
|
|
|
49
51
|
## 隐私
|
|
50
52
|
|
|
51
|
-
- helper 只监听 `127.0.0.1`,校验 `Host`。
|
|
53
|
+
- helper 只监听 `127.0.0.1`,校验 `Host`;带浏览器 `Origin` 的请求一律拒绝,写请求必须是 `application/json`。
|
|
54
|
+
- 网关密钥从 magpie 的 `caller-keys.json` 只读取用,只放内存,不落日志。
|
|
52
55
|
- 日志只有时间、事件、耗时、字数,**不记原文**。
|
|
53
56
|
- 取词后会把剪贴板全量还原(图片等非 HGLOBAL 格式除外)。
|
|
54
57
|
|
|
@@ -60,6 +63,12 @@ Ctrl+C 在这些程序里有副作用,命中时只提示「该应用不支持
|
|
|
60
63
|
|
|
61
64
|
helper 只在 magpie 启动插件时被拉起,magpie 不开它就不会常驻,也不写注册表。
|
|
62
65
|
|
|
66
|
+
## 更新
|
|
67
|
+
|
|
68
|
+
- 0.2.1:修安全漏洞:本地接口拒绝带浏览器 `Origin` 的请求,写请求必须是 `application/json`;术语表只接收正文(`glossary`),不再按路径读本地文件。`package.json` 去掉 BOM。
|
|
69
|
+
- 0.2.0:浮窗加了浅绿描边;正文改成整行取整、滚动条常驻,长译文不会再被切掉半行;顶部可以直接按住拖动(之前 `WM_NCHITTEST` 把屏幕坐标当客户区坐标用,拖不动);标题改父窗口自绘,修掉连续取词时的残影。
|
|
70
|
+
- 0.1.1:设置页和 `magpie.summary` 补全,能被 magpie 的 Discover 展示。
|
|
71
|
+
|
|
63
72
|
## License
|
|
64
73
|
|
|
65
74
|
MIT
|
package/bin/helper.exe
CHANGED
|
Binary file
|
package/index.mjs
CHANGED
|
@@ -18,13 +18,13 @@ const alive = async (port) => {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
//
|
|
22
|
-
//
|
|
21
|
+
// 包里带了 bin/helper.exe 就以包里为准(能跑到这里说明端口上没有活着的 helper):
|
|
22
|
+
// 早先是"已装过就沿用",结果老用户升级插件后永远停在第一次装的那份旧 exe。
|
|
23
|
+
// 装不进去(旧 helper 还留着文件锁)就退回用已装的,至少能用。
|
|
23
24
|
const ensureHelper = () => {
|
|
24
25
|
const installed = join(home, "helper.exe")
|
|
25
|
-
if (existsSync(installed)) return installed
|
|
26
26
|
const bundled = join(here, "bin", "helper.exe")
|
|
27
|
-
if (!existsSync(bundled)) return ""
|
|
27
|
+
if (!existsSync(bundled)) return existsSync(installed) ? installed : ""
|
|
28
28
|
try {
|
|
29
29
|
mkdirSync(home, { recursive: true })
|
|
30
30
|
copyFileSync(bundled, installed)
|
|
@@ -32,7 +32,7 @@ const ensureHelper = () => {
|
|
|
32
32
|
const uninstall = join(here, "bin", "uninstall.ps1")
|
|
33
33
|
if (existsSync(uninstall)) copyFileSync(uninstall, join(home, "uninstall.ps1"))
|
|
34
34
|
} catch {
|
|
35
|
-
return
|
|
35
|
+
return existsSync(installed) ? installed : bundled
|
|
36
36
|
}
|
|
37
37
|
return installed
|
|
38
38
|
}
|
|
@@ -51,7 +51,13 @@ export default {
|
|
|
51
51
|
"helper 未安装:运行仓库里的 scripts/install.ps1,或安装带 bin/helper.exe 的发行包",
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
// 页面只能写 magpie.options,所以设置由这里转成命令行交给 helper(helper 落地成自己的 settings.json)
|
|
55
|
+
const args = ["--port", String(port)]
|
|
56
|
+
for (const k of ["hotkey", "model", "target", "glossary"]) {
|
|
57
|
+
const v = options?.[k]
|
|
58
|
+
if (v) args.push(`--${k === "glossary" ? "glossary-text" : k}`, String(v))
|
|
59
|
+
}
|
|
60
|
+
spawn(exe, args, {
|
|
55
61
|
detached: true,
|
|
56
62
|
stdio: "ignore",
|
|
57
63
|
windowsHide: true,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
{
|
|
2
2
|
"name": "magpie-select-translate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "划词翻译:选中文字按热键,鼠标旁浮窗流式显示 magpie 模型的译文。Select-to-translate popover for magpie: hit a hotkey on any selection and the translation streams next to your cursor.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|
|
7
7
|
"files": [
|
|
@@ -23,10 +23,15 @@
|
|
|
23
23
|
"magpie": ">=0.1.1340"
|
|
24
24
|
},
|
|
25
25
|
"magpie": {
|
|
26
|
+
"name": "Select Translate",
|
|
27
|
+
"summary": {
|
|
28
|
+
"en": "Select text anywhere and press a hotkey: a popover next to the cursor streams the translation from magpie's own models. Ships the Windows helper, so there is nothing else to install.",
|
|
29
|
+
"zh": "在任意程序里选中文字按热键,鼠标旁的浮窗流式显示 magpie 模型的译文。包内自带 Windows helper,装上就能用。"
|
|
30
|
+
},
|
|
26
31
|
"page": {
|
|
27
32
|
"title": "Translate",
|
|
28
33
|
"titles": {
|
|
29
|
-
"zh": "
|
|
34
|
+
"zh": "划词翻译",
|
|
30
35
|
"en": "Translate"
|
|
31
36
|
},
|
|
32
37
|
"file": "page/index.html"
|
|
@@ -36,7 +41,7 @@
|
|
|
36
41
|
"hotkey": "Alt+D",
|
|
37
42
|
"model": "",
|
|
38
43
|
"target": "auto",
|
|
39
|
-
"
|
|
44
|
+
"glossary": ""
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
|
-
}
|
|
47
|
+
}
|
package/page/index.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
h1 { font-size: 16px; margin: 0 0 4px; }
|
|
13
13
|
p.sub { margin: 0 0 18px; opacity: .7; font-size: 12px; }
|
|
14
14
|
label { display: block; margin: 14px 0 4px; font-size: 12px; opacity: .8; }
|
|
15
|
-
input, select {
|
|
15
|
+
input, select, textarea {
|
|
16
16
|
width: 100%; box-sizing: border-box; padding: 7px 9px; font: inherit;
|
|
17
17
|
border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
|
|
18
18
|
border-radius: 8px; background: transparent; color: inherit;
|
|
@@ -46,20 +46,20 @@
|
|
|
46
46
|
<label for="model">模型 id(留空用网关第一个模型)</label>
|
|
47
47
|
<input id="model" placeholder="group/deepseek-v4.1-flash">
|
|
48
48
|
|
|
49
|
-
<label for="
|
|
50
|
-
<
|
|
49
|
+
<label for="glossary">术语表(每行 原文=译文,只存在 helper 的设置里,不读任何文件)</label>
|
|
50
|
+
<textarea id="glossary" rows="4" placeholder="magpie=喜鹊"></textarea>
|
|
51
51
|
|
|
52
52
|
<label for="port">helper 端口</label>
|
|
53
53
|
<input id="port" type="number" placeholder="3477">
|
|
54
54
|
|
|
55
55
|
<div id="status"></div>
|
|
56
56
|
<p class="hint">
|
|
57
|
-
|
|
58
|
-
helper 未安装时运行 <code>scripts/install.ps1</code>。
|
|
57
|
+
设置页在沙箱里不能联网,所以这里只写 magpie 的选项;helper 下次启动时按这些选项运行,改完重启 helper 生效。
|
|
58
|
+
翻译状态请按热键看浮窗。helper 未安装时运行 <code>scripts/install.ps1</code>。
|
|
59
59
|
</p>
|
|
60
60
|
|
|
61
61
|
<script>
|
|
62
|
-
const fields = ["hotkey", "model", "target", "
|
|
62
|
+
const fields = ["hotkey", "model", "target", "glossary", "port"]
|
|
63
63
|
const $ = (id) => document.getElementById(id)
|
|
64
64
|
let timer = null
|
|
65
65
|
|