@@ -32,6 +32,9 @@ class I18nCaseDetail {
3232 // 更新页面中的按钮标签
3333 this . updateTestCaseButtons ( ) ;
3434
35+ // 强制替换所有JavaScript中的硬编码状态文本
36+ this . patchJavaScriptTexts ( ) ;
37+
3538 // 在DOM加载完成后动态处理"测试完成"的显示
3639 setTimeout ( ( ) => {
3740 const resultMessage = document . querySelector ( '.result-message' ) ;
@@ -44,9 +47,72 @@ class I18nCaseDetail {
4447 if ( stopButton ) {
4548 stopButton . textContent = this . i18n . currentLang === 'zh-CN' ? '停止测试' : 'Stop Test' ;
4649 }
50+
51+ // 替换导航菜单中的文本
52+ this . updateNavigation ( ) ;
4753 } , 100 ) ;
4854 }
4955
56+ // 替换导航菜单中的文本
57+ updateNavigation ( ) {
58+ const homeLink = document . querySelector ( 'a[href="../../index.html"]' ) ;
59+ if ( homeLink ) {
60+ const icon = homeLink . querySelector ( 'i' ) ;
61+ homeLink . innerHTML = '' ;
62+ if ( icon ) homeLink . appendChild ( icon ) ;
63+ homeLink . appendChild ( document . createTextNode ( ' ' + this . i18n . t ( 'nav.home' ) ) ) ;
64+ }
65+
66+ const casesLink = document . querySelector ( 'a[href="../../cases/index.html"]' ) ;
67+ if ( casesLink ) {
68+ const icon = casesLink . querySelector ( 'i' ) ;
69+ casesLink . innerHTML = '' ;
70+ if ( icon ) casesLink . appendChild ( icon ) ;
71+ casesLink . appendChild ( document . createTextNode ( ' ' + this . i18n . t ( 'nav.testCases' ) ) ) ;
72+ }
73+ }
74+
75+ // 替换JavaScript中的硬编码中文文本
76+ patchJavaScriptTexts ( ) {
77+ // 获取当前语言,保存为常量
78+ const currentLang = this . i18n . currentLang ;
79+
80+ // 直接替换脚本中的常见状态文本
81+ const scripts = document . querySelectorAll ( 'script:not([src])' ) ;
82+ scripts . forEach ( script => {
83+ if ( script . textContent . includes ( '测试运行中' ) || script . textContent . includes ( '测试完成' ) ) {
84+ // 创建一个新的脚本元素,替换原始脚本中的状态文本
85+ const newScript = document . createElement ( 'script' ) ;
86+ let newContent = script . textContent ;
87+
88+ // 替换常见状态文本
89+ newContent = newContent . replace ( / [ ' " ] 测 试 运 行 中 \. \. \. [ ' " ] | [ ' " ] 测 试 运 行 中 ...[ ' " ] | [ ' " ] T e s t R u n n i n g ...[ ' " ] / ,
90+ `(window.currentLang === 'zh-CN' ? '测试运行中...' : 'Test Running...')` ) ;
91+
92+ newContent = newContent . replace ( / [ ' " ] 测 试 完 成 [ ' " ] | [ ' " ] T e s t C o m p l e t e [ ' " ] / ,
93+ `(window.currentLang === 'zh-CN' ? '测试完成' : 'Test Complete')` ) ;
94+
95+ // setInterval特有的文本
96+ if ( document . querySelector ( '.test-container h2' ) ?. textContent . includes ( 'setInterval' ) ) {
97+ newContent = newContent . replace ( / [ ' " ] 测 试 期 间 未 检 测 到 任 何 断 点 暂 停 \. [ ' " ] / ,
98+ `(window.currentLang === 'zh-CN' ? '测试期间未检测到任何断点暂停。' : 'No breakpoint pauses detected during the test.')` ) ;
99+
100+ newContent = newContent . replace ( / [ ' " ] 测 试 期 间 检 测 到 执 行 被 断 点 中 断 \. [ ' " ] / ,
101+ `(window.currentLang === 'zh-CN' ? '测试期间检测到执行被断点中断。' : 'Execution was interrupted by a breakpoint during the test.')` ) ;
102+
103+ newContent = newContent . replace ( / [ ' " ] 停 止 测 试 [ ' " ] | [ ' " ] S t o p T e s t [ ' " ] / ,
104+ `(window.currentLang === 'zh-CN' ? '停止测试' : 'Stop Test')` ) ;
105+ }
106+
107+ // 在脚本开头添加当前语言变量
108+ newContent = `window.currentLang = "${ currentLang } ";\n` + newContent ;
109+
110+ newScript . textContent = newContent ;
111+ script . parentNode . replaceChild ( newScript , script ) ;
112+ }
113+ } ) ;
114+ }
115+
50116 // 更新测试用例标题
51117 updateCaseTitle ( titleElement ) {
52118 const titleText = titleElement . textContent . trim ( ) ;
@@ -172,8 +238,21 @@ class I18nCaseDetail {
172238 const codeBlock = document . querySelector ( '.code-block' ) ;
173239 if ( ! codeBlock ) return ;
174240
241+ // 创建完整的样式覆盖,强制覆盖原有的content属性值
175242 const style = document . createElement ( 'style' ) ;
176- style . textContent = `.code-block::before { content: "${ this . i18n . t ( 'testCase.codeLabel' ) } "; }` ;
243+ style . textContent = `
244+ .code-block::before {
245+ content: "${ this . i18n . t ( 'testCase.codeLabel' ) } " !important;
246+ position: absolute;
247+ top: -12px;
248+ left: 1rem;
249+ background: var(--primary-color);
250+ color: white;
251+ padding: 0.25rem 0.75rem;
252+ border-radius: 12px;
253+ font-size: 0.875rem;
254+ }
255+ ` ;
177256
178257 // 检查是否已经添加过样式
179258 const existingStyle = document . querySelector ( 'style[data-i18n-code-label]' ) ;
0 commit comments