@@ -41,23 +41,54 @@ export class ConfigurationComponent implements LanguageUpdateable {
4141 // 检查是否已经存在配置窗口
4242 const existingModal = document . getElementById ( "jsrei-js-script-hook-configuration-modal-window" ) ;
4343 if ( existingModal ) {
44- configUILogger . debug ( '配置窗口已经打开,不再创建新窗口 ' ) ;
44+ configUILogger . debug ( '配置窗口已经存在于DOM中 ' ) ;
4545
4646 // 如果窗口已存在但不可见,则显示它
4747 if ( existingModal . style . display === 'none' ) {
4848 configUILogger . debug ( '窗口存在但不可见,将其显示' ) ;
4949 existingModal . style . display = 'block' ;
50- configUILogger . debug ( '重新显示已存在的窗口' ) ;
50+
51+ // 重新验证内容容器是否存在
52+ const contentContainer = document . getElementById ( 'js-script-hook-configuration-content' ) ;
53+ if ( ! contentContainer ) {
54+ configUILogger . error ( '无法找到内容容器元素,尝试重新创建整个配置界面' ) ;
55+ // 如果内容容器不存在,我们需要先删除现有的模态框,然后重建
56+ existingModal . remove ( ) ;
57+ // 清除modal-root并重新创建
58+ const modalRoot = document . getElementById ( 'js-script-hook-modal-root' ) ;
59+ if ( modalRoot ) {
60+ modalRoot . remove ( ) ;
61+ }
62+ // 继续执行后面的创建逻辑
63+ } else {
64+ configUILogger . debug ( '重新显示已存在的窗口,内容容器正常' ) ;
65+
66+ // 使窗口有一个轻微闪动效果,引导用户注意
67+ const scrollableDiv = existingModal . querySelector ( '.js-script-hook-scrollable-div' ) as HTMLElement ;
68+ if ( scrollableDiv ) {
69+ scrollableDiv . style . setProperty ( 'box-shadow' , '0 0 15px rgba(0,123,255,0.8)' ) ;
70+ setTimeout ( ( ) => {
71+ scrollableDiv . style . setProperty ( 'box-shadow' , '0 6px 16px rgba(0,0,0,0.2)' ) ;
72+ } , 300 ) ;
73+ }
74+
75+ return ;
76+ }
77+ } else {
78+ // 窗口已经可见,只做闪动效果
79+ configUILogger . debug ( '窗口已经可见,不再创建新窗口' ) ;
80+
81+ // 使窗口有一个轻微闪动效果,引导用户注意
82+ const scrollableDiv = existingModal . querySelector ( '.js-script-hook-scrollable-div' ) as HTMLElement ;
83+ if ( scrollableDiv ) {
84+ scrollableDiv . style . setProperty ( 'box-shadow' , '0 0 15px rgba(0,123,255,0.8)' ) ;
85+ setTimeout ( ( ) => {
86+ scrollableDiv . style . setProperty ( 'box-shadow' , '0 6px 16px rgba(0,0,0,0.2)' ) ;
87+ } , 300 ) ;
88+ }
89+
90+ return ;
5191 }
52-
53- // 使窗口有一个轻微闪动效果,引导用户注意
54- const scrollableDiv = existingModal . querySelector ( '.js-script-hook-scrollable-div' ) as HTMLElement ;
55- scrollableDiv . style . setProperty ( 'box-shadow' , '0 0 15px rgba(0,123,255,0.8)' ) ;
56- setTimeout ( ( ) => {
57- scrollableDiv . style . setProperty ( 'box-shadow' , '0 6px 16px rgba(0,0,0,0.2)' ) ;
58- } , 300 ) ;
59-
60- return ;
6192 }
6293
6394 // 添加样式
@@ -237,8 +268,12 @@ export class ConfigurationComponent implements LanguageUpdateable {
237268 */
238269 private closeModalWindow ( ) : void {
239270 const element = document . getElementById ( "jsrei-js-script-hook-configuration-modal-window" ) ;
240- if ( element && element . parentNode ) {
241- element . parentNode . removeChild ( element ) ;
271+ if ( element ) {
272+ // 不再从DOM中移除元素,而是仅仅隐藏它
273+ element . style . display = 'none' ;
274+ configUILogger . debug ( '配置窗口已隐藏,但保留在DOM中以便稍后重用' ) ;
275+ } else {
276+ configUILogger . warn ( '尝试关闭模态窗口但未找到元素' ) ;
242277 }
243278 }
244279
@@ -389,24 +424,40 @@ export class ConfigurationComponent implements LanguageUpdateable {
389424 * 销毁组件
390425 */
391426 public destroy ( ) : void {
427+ configUILogger . debug ( '开始销毁配置组件...' ) ;
428+
392429 // 取消语言更新订阅
393430 LanguageEventManager . getInstance ( ) . unsubscribe ( this . componentId ) ;
431+ configUILogger . debug ( '已取消语言更新订阅' ) ;
394432
395433 // 销毁TabComponent
396- if ( 'destroy' in this . tabComponent ) {
434+ if ( this . tabComponent && 'destroy' in this . tabComponent ) {
397435 ( this . tabComponent as unknown as LanguageUpdateable ) . destroy ( ) ;
436+ configUILogger . debug ( '已销毁标签页组件' ) ;
398437 }
399438
400439 // 移除配置窗口
401440 const modalWindow = document . getElementById ( "jsrei-js-script-hook-configuration-modal-window" ) ;
402441 if ( modalWindow ) {
442+ // 销毁时确实要从DOM中移除,而不仅仅是隐藏
403443 modalWindow . remove ( ) ;
444+ configUILogger . debug ( '已移除配置窗口' ) ;
445+ }
446+
447+ // 移除根容器
448+ const rootElement = document . getElementById ( 'js-script-hook-modal-root' ) ;
449+ if ( rootElement ) {
450+ rootElement . remove ( ) ;
451+ configUILogger . debug ( '已移除根容器' ) ;
404452 }
405453
406454 // 移除样式
407- const style = document . getElementById ( "js-script-hook- configuration-style" ) ;
455+ const style = document . getElementById ( "configuration-component -style" ) ;
408456 if ( style ) {
409457 style . remove ( ) ;
458+ configUILogger . debug ( '已移除样式' ) ;
410459 }
460+
461+ configUILogger . debug ( '配置组件销毁完成' ) ;
411462 }
412463}
0 commit comments