11// Popup 界面控制器
22class 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 控制器
798819document . addEventListener ( 'DOMContentLoaded' , ( ) => {
799820 new PopupController ( ) ;
800- } ) ;
821+ } ) ;
0 commit comments