Skip to content

Commit b07689f

Browse files
committed
feat: 更新欢迎提示文本和显示时长 - 修改popup.html中的安装完成通知文字,确保欢迎toast持续显示5秒
1 parent 28c97cd commit b07689f

4 files changed

Lines changed: 122 additions & 16 deletions

File tree

background.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,39 @@ class ScreenshotTranslator {
66
console.log('ScreenshotTranslator constructor called');
77
this.isProcessing = false;
88
this.setupMessageListeners();
9+
this.setupInstallListener();
910
console.log('ScreenshotTranslator initialized');
1011
}
1112

13+
setupInstallListener() {
14+
chrome.runtime.onInstalled.addListener((details) => {
15+
console.log('Extension installed or updated:', details);
16+
if (details.reason === 'install') {
17+
// 使用 storage 存储安装标记,popup 打开时会检查
18+
chrome.storage.local.set({ shouldShowWelcome: true });
19+
20+
// 安装完成后立即显示欢迎通知,持续5秒
21+
chrome.notifications.create({
22+
type: 'basic',
23+
iconUrl: 'icons/icon16.png',
24+
title: 'QuickTranslate 安装完成',
25+
message: 'QuickTranslate已安装!请点击插件图标开始使用。温馨提示:请把插件固定在快捷工具栏方便使用。',
26+
requireInteraction: false,
27+
silent: false
28+
});
29+
30+
// 5秒后自动关闭通知
31+
setTimeout(() => {
32+
chrome.notifications.getAll((notifications) => {
33+
Object.keys(notifications).forEach(id => {
34+
chrome.notifications.clear(id);
35+
});
36+
});
37+
}, 5000);
38+
}
39+
});
40+
}
41+
1242
setupMessageListeners() {
1343
console.log('Setting up message listeners...');
1444
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {

popup.css

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,55 @@ body {
151151
position: relative;
152152
}
153153

154+
/* 欢迎提示框 */
155+
.welcome-toast {
156+
position: fixed;
157+
top: 20px;
158+
right: 20px;
159+
display: flex;
160+
align-items: center;
161+
gap: 12px;
162+
padding: 12px 16px;
163+
background: white;
164+
border-radius: 12px;
165+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
166+
z-index: 1000001;
167+
animation: toastEnter 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
168+
}
169+
170+
.welcome-toast .toast-icon {
171+
font-size: 24px;
172+
color: #667eea;
173+
}
174+
175+
.welcome-toast .toast-message {
176+
font-size: 13px;
177+
color: #4a4a4a;
178+
line-height: 1.4;
179+
}
180+
181+
.welcome-toast .toast-close {
182+
font-size: 20px;
183+
color: #999;
184+
cursor: pointer;
185+
margin-left: auto;
186+
transition: color 0.2s;
187+
}
188+
189+
.welcome-toast .toast-close:hover {
190+
color: #333;
191+
}
192+
193+
.welcome-toast.hidden {
194+
opacity: 0;
195+
pointer-events: none;
196+
}
197+
198+
@keyframes toastEnter {
199+
0% { opacity: 0; transform: translateY(20px) scale(0.9); }
200+
100% { opacity: 1; transform: translateY(0) scale(1); }
201+
}
202+
154203
.main-section::before {
155204
content: '';
156205
position: absolute;

popup.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ <h3>高級設置</h3>
176176
</div>
177177
</div>
178178

179+
<div id="welcome-toast" class="welcome-toast hidden">
180+
<div class="toast-icon"></div>
181+
<div class="toast-message" id="install-message">插件已安装,请点击扩展图标将其固定到工具栏</div>
182+
<div class="toast-close">×</div>
183+
</div>
184+
179185
<script src="popup.js"></script>
180186
</body>
181187
</html>

popup.js

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
// Popup 界面控制器
22
class PopupController {
3-
constructor() {
4-
this.elements = {};
5-
this.settings = {};
6-
this.init();
7-
}
3+
constructor() {
4+
this.elements = {};
5+
this.settings = {};
6+
this.init();
7+
}
88

99
init() {
1010
this.bindElements();
1111
this.bindEvents();
1212
this.loadSettings();
13+
// 显示欢迎 toast 5 秒
14+
this.showWelcomeToast();
15+
}
16+
17+
showWelcomeToast() {
18+
const welcomeToast = document.getElementById('welcome-toast');
19+
if (welcomeToast) {
20+
welcomeToast.classList.remove('hidden');
21+
// 5 秒后隐藏
22+
setTimeout(() => {
23+
welcomeToast.classList.add('hidden');
24+
}, 5000);
25+
26+
// 点击关闭按钮手动关闭
27+
const closeBtn = welcomeToast.querySelector('.toast-close');
28+
if (closeBtn) {
29+
closeBtn.onclick = () => {
30+
welcomeToast.classList.add('hidden');
31+
};
32+
}
33+
}
1334
}
1435

1536
bindElements() {
@@ -133,7 +154,7 @@ class PopupController {
133154

134155
// 自定義模型輸入框變更時標記未保存
135156
this.elements.llmModelCustom.addEventListener('input', () => this.showUnsavedChanges());
136-
157+
137158
// 自定義模型輸入框失去焦點時,如果為空則顯示下拉框
138159
this.elements.llmModelCustom.addEventListener('blur', () => {
139160
const customValue = this.elements.llmModelCustom.value.trim();
@@ -394,7 +415,7 @@ class PopupController {
394415
this.elements.apiProvider.value = this.settings.apiProvider || 'google';
395416
this.elements.autoCopy.checked = this.settings.autoCopy || false;
396417
this.elements.showConfidence.checked = this.settings.showConfidence !== false;
397-
418+
398419
// 更新快捷面板設置
399420
this.elements.quickPanelEnabled.checked = this.settings.quickPanelEnabled !== false;
400421
this.elements.minSelectionLength.value = this.settings.minSelectionLength || 2;
@@ -409,12 +430,12 @@ class PopupController {
409430
if (this.settings.llmConfig) {
410431
this.elements.llmBaseUrl.value = this.settings.llmConfig.baseUrl || '';
411432
const savedModel = this.settings.llmConfig.model || '';
412-
433+
413434
if (savedModel) {
414435
// 檢查模型是否已在下拉列表中
415436
const options = this.elements.llmModel.options;
416437
let found = false;
417-
438+
418439
for (let i = 0; i < options.length; i++) {
419440
if (options[i].value === savedModel) {
420441
this.elements.llmModel.value = savedModel;
@@ -425,7 +446,7 @@ class PopupController {
425446
break;
426447
}
427448
}
428-
449+
429450
if (!found) {
430451
// 模型不在列表中,使用自定義輸入框顯示
431452
this.elements.llmModel.classList.add('hidden');
@@ -553,7 +574,7 @@ class PopupController {
553574
const modelFromDropdown = this.elements.llmModel.value;
554575
const modelFromCustomInput = this.elements.llmModelCustom.value.trim();
555576
const finalModel = isCustomInputVisible ? modelFromCustomInput : modelFromDropdown;
556-
577+
557578
if (!baseUrl) {
558579
this.showStatus('請填寫 Base URL', 'error');
559580
return;
@@ -588,23 +609,23 @@ class PopupController {
588609
const isCustomInputVisible = !this.elements.llmModelCustom.classList.contains('hidden');
589610
const dropdownValue = this.elements.llmModel.value;
590611
const customValue = this.elements.llmModelCustom.value.trim();
591-
612+
592613
// 如果自定義輸入框可見,使用自定義輸入的值
593614
// 否則使用下拉框的值(但排除 __custom__ 選項)
594615
let finalModel = isCustomInputVisible ? customValue : dropdownValue;
595-
616+
596617
// 確保不會保存 __custom__ 這個佔位符
597618
if (finalModel === '__custom__') {
598619
finalModel = customValue || '';
599620
}
600-
621+
601622
console.log('Popup: Saving LLM model config:', {
602623
isCustomInputVisible,
603624
dropdownValue,
604625
customValue,
605626
finalModel
606627
});
607-
628+
608629
return finalModel;
609630
})()
610631
} : this.settings.llmConfig
@@ -797,4 +818,4 @@ class PopupController {
797818
// 初始化 Popup 控制器
798819
document.addEventListener('DOMContentLoaded', () => {
799820
new PopupController();
800-
});
821+
});

0 commit comments

Comments
 (0)