Initial commit: 译泡 PopLingo v1.0.0

AI 划词翻译 Chrome 扩展(Manifest V3):
- 支持 DeepSeek/OpenAI/Kimi/智谱/通义/Gemini/Claude/Ollama 等 10 种服务商
- 流式输出、左右分栏对照、原文一键展开收起
- 划词图标/自动翻译/Alt+T 快捷键/右键菜单四种触发方式
This commit is contained in:
2026-09-17 00:43:32 +08:00
commit eb00b23de8
16 changed files with 1486 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
width: 300px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
background: #f8fafc;
color: #111827;
}
.head {
display: flex; align-items: center; justify-content: space-between;
padding: 14px 16px 12px;
background: linear-gradient(135deg, #4f46e5, #8b5cf6);
color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 6px; }
.brand h1 { font-size: 14px; font-weight: 700; }
.status { font-size: 11px; opacity: .85; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
position: absolute; inset: 0; background: rgba(255,255,255,.35);
border-radius: 99px; cursor: pointer; transition: background .2s;
}
.slider::before {
content: ''; position: absolute; left: 3px; top: 3px;
width: 16px; height: 16px; border-radius: 50%; background: #fff;
transition: transform .2s;
}
.switch input:checked + .slider { background: #22c55e; }
.switch input:checked + .slider::before { transform: translateX(18px); }
.provider { margin: 10px 12px 0; padding: 4px 12px; background: #fff; border-radius: 10px; border: 1px solid #e5e7eb; }
.row {
display: flex; align-items: center; justify-content: space-between;
padding: 8px 0; font-size: 12.5px;
}
.row + .row { border-top: 1px solid #f3f4f6; }
.label { color: #6b7280; }
.value { font-weight: 600; color: #111827; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; font-weight: 500; color: #4f46e5; }
.warn { color: #f59e0b; }
.ok { color: #10b981; }
.form { display: grid; gap: 8px; padding: 10px 12px 4px; }
.field { display: grid; gap: 4px; font-size: 12px; color: #6b7280; }
.field select {
padding: 7px 10px; border-radius: 8px; border: 1px solid #e5e7eb;
background: #fff; font-size: 13px; color: #111827; outline: none; cursor: pointer;
}
.field select:focus { border-color: #8b5cf6; box-shadow: 0 0 0 3px rgba(139,92,246,.15); }
.foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 14px; }
.btn {
border: none; cursor: pointer; font-size: 12.5px; font-weight: 600;
padding: 8px 14px; border-radius: 8px; background: #eef2ff; color: #4f46e5;
transition: all .15s;
}
.btn:hover { background: #e0e7ff; transform: translateY(-1px); }
.hint { font-size: 10.5px; color: #9ca3af; }
+59
View File
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="popup.css" />
</head>
<body>
<header class="head">
<div class="brand">
<img src="../icons/icon32.png" alt="" width="22" height="22" />
<div>
<h1>译泡 PopLingo</h1>
<span id="statusText" class="status">已开启</span>
</div>
</div>
<label class="switch">
<input type="checkbox" id="enabledToggle" />
<span class="slider"></span>
</label>
</header>
<section class="provider">
<div class="row">
<span class="label">服务商</span>
<span id="providerName" class="value">DeepSeek</span>
</div>
<div class="row">
<span class="label">模型</span>
<span id="modelName" class="value mono">deepseek-chat</span>
</div>
<div class="row" id="keyRow">
<span class="label">API Key</span>
<span id="keyStatus" class="value warn">未配置</span>
</div>
</section>
<section class="form">
<label class="field">
<span>目标语言</span>
<select id="targetLang"></select>
</label>
<label class="field">
<span>触发方式</span>
<select id="triggerMode">
<option value="icon">划词后点图标</option>
<option value="auto">划词后自动翻译</option>
<option value="shortcut">仅快捷键 Alt+T</option>
</select>
</label>
</section>
<footer class="foot">
<button id="openOptions" class="btn primary">⚙ 模型设置</button>
<span class="hint">选中文字试试 · Esc 关闭弹窗</span>
</footer>
<script src="popup.js"></script>
</body>
</html>
+48
View File
@@ -0,0 +1,48 @@
/* global chrome */
const LANGS = ['简体中文', '繁體中文', 'English', '日本語', '한국어', 'Français', 'Deutsch', 'Español', 'Português', 'Italiano', 'Русский', 'العربية', 'हिन्दी', 'ไทย', 'Việt Nam', 'Indonesia'];
const PRESETS = {
deepseek: 'DeepSeek', openai: 'OpenAI', kimi: '月之暗面 Kimi', zhipu: '智谱 GLM',
qwen: '通义千问', siliconflow: '硅基流动', gemini: 'Google Gemini',
anthropic: 'Anthropic Claude', ollama: 'Ollama(本地)', custom: '自定义(OpenAI 兼容)'
};
const $ = id => document.getElementById(id);
async function init() {
const cfg = await chrome.storage.sync.get({
enabled: true, preset: 'deepseek', model: '', apiKey: '',
targetLang: '简体中文', triggerMode: 'icon'
});
const langSel = $('targetLang');
LANGS.forEach(l => {
const o = document.createElement('option');
o.value = l; o.textContent = l;
langSel.appendChild(o);
});
langSel.value = cfg.targetLang;
$('triggerMode').value = cfg.triggerMode;
$('enabledToggle').checked = cfg.enabled;
updateStatus(cfg.enabled);
$('providerName').textContent = PRESETS[cfg.preset] || cfg.preset;
$('modelName').textContent = cfg.model || '(未设置)';
$('keyStatus').textContent = cfg.apiKey ? '已配置' : '未配置';
$('keyStatus').className = 'value ' + (cfg.apiKey ? 'ok' : 'warn');
$('enabledToggle').addEventListener('change', e => {
chrome.storage.sync.set({ enabled: e.target.checked });
updateStatus(e.target.checked);
});
langSel.addEventListener('change', () => chrome.storage.sync.set({ targetLang: langSel.value }));
$('triggerMode').addEventListener('change', () => chrome.storage.sync.set({ triggerMode: $('triggerMode').value }));
$('openOptions').addEventListener('click', () => chrome.runtime.openOptionsPage());
}
function updateStatus(on) {
$('statusText').textContent = on ? 'AI 划词翻译 · 已开启' : 'AI 划词翻译 · 已停用';
}
init();