Skip to content

Commit 6040826

Browse files
committed
fix: 修复URL匹配测试功能在语言切换后显示不正确的问题\n\n1. 在URL匹配下拉菜单和测试按钮中添加获取最新语言设置的逻辑\n2. 添加测试结果匹配/不匹配的多语言支持\n3. 确保URL测试对话框始终显示正确的语言
1 parent 377c095 commit 6040826

File tree

4 files changed

+86
-23
lines changed

4 files changed

+86
-23
lines changed

src/config/ui/component/debugger/events.ts

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getGlobalConfig } from "../../../config";
22
import { DebuggerConfig, UrlPatternType } from './types';
33
import { Language } from '../language';
4+
import { LanguageEventManager } from '../language-event';
45
import {
56
SelectComponent,
67
SelectOption,
@@ -141,9 +142,12 @@ export function bindDebuggerEvents(
141142
`${debuggerInformation.id}-url-pattern-test`,
142143
language.debugger_config.urlPatternTest,
143144
function() {
145+
// 获取当前最新的语言设置,而不是使用闭包中的language对象
146+
const currentLanguage = LanguageEventManager.getInstance().getCurrentLanguage() || language;
147+
144148
const inputDialog = InputDialogComponent.getInstance();
145149
inputDialog.show(
146-
language.debugger_config.urlPatternTestPrompt,
150+
currentLanguage.debugger_config.urlPatternTestPrompt,
147151
'',
148152
(confirmed: boolean, testUrl: string) => {
149153
if (!confirmed || !testUrl) return;
@@ -155,18 +159,18 @@ export function bindDebuggerEvents(
155159

156160
const alertDialog = AlertDialogComponent.getInstance();
157161
alertDialog.show(
158-
language.debugger_config.urlPatternTestResult,
159-
result ? '✅ Match' : '❌ Not Match',
160-
language.basic.closeButton
162+
currentLanguage.debugger_config.urlPatternTestResult,
163+
result ? currentLanguage.debugger_config.urlPatternTestMatch : currentLanguage.debugger_config.urlPatternTestNotMatch,
164+
currentLanguage.basic.closeButton
161165
);
162166
} catch (e: unknown) {
163167
eventsLogger.error(`测试URL匹配模式时出错: ${e}`);
164168
}
165169
},
166170
'',
167-
language.debugger_config.urlPatternTextPlaceholder,
168-
language.basic.testButton,
169-
language.basic.cancelButton
171+
currentLanguage.debugger_config.urlPatternTextPlaceholder,
172+
currentLanguage.basic.testButton,
173+
currentLanguage.basic.inputDialog.defaultCancelText
170174
);
171175
},
172176
'primary',
@@ -179,26 +183,48 @@ export function bindDebuggerEvents(
179183
// 为URL pattern输入绑定事件
180184
const urlPatternTextContainer = element.querySelector(`#${debuggerInformation.id}-url-pattern-input-container`);
181185
if (urlPatternTextContainer) {
182-
urlPatternTextContainer.appendChild(
183-
inputComponent.render(
184-
`${debuggerInformation.id}-url-pattern-text`,
185-
debuggerInformation.urlPattern,
186-
language.debugger_config.urlPatternTextPlaceholder,
187-
undefined,
188-
(value: string) => {
189-
debuggerInformation.urlPattern = value;
190-
186+
const inputElement = inputComponent.render(
187+
`${debuggerInformation.id}-url-pattern-text`,
188+
debuggerInformation.urlPattern,
189+
language.debugger_config.urlPatternTextPlaceholder,
190+
undefined,
191+
(value: string) => {
192+
debuggerInformation.urlPattern = value;
193+
194+
// 保存配置
195+
const config = getGlobalConfig();
196+
const debuggerItem = config.findDebuggerById(debuggerInformation.id);
197+
if (debuggerItem) {
198+
debuggerItem.urlPattern = value;
199+
debuggerItem.updateTime = new Date().getTime();
200+
config.persist();
201+
}
202+
}
203+
);
204+
205+
urlPatternTextContainer.appendChild(inputElement);
206+
207+
// 在初始化时检查是否需要禁用输入框
208+
setTimeout(() => {
209+
const urlPatternInput = element.querySelector(`#${debuggerInformation.id}-url-pattern-text`) as HTMLInputElement;
210+
if (urlPatternInput && debuggerInformation.urlPatternType === 'match-all') {
211+
urlPatternInput.disabled = true;
212+
urlPatternInput.value = '';
213+
urlPatternInput.placeholder = language.debugger_config.urlPatternMatchAllDisabledText;
214+
// 清空配置中的URL匹配关键字
215+
if (debuggerInformation.urlPattern) {
216+
debuggerInformation.urlPattern = '';
191217
// 保存配置
192218
const config = getGlobalConfig();
193219
const debuggerItem = config.findDebuggerById(debuggerInformation.id);
194220
if (debuggerItem) {
195-
debuggerItem.urlPattern = value;
221+
debuggerItem.urlPattern = '';
196222
debuggerItem.updateTime = new Date().getTime();
197223
config.persist();
198224
}
199225
}
200-
)
201-
);
226+
}
227+
}, 0);
202228
}
203229

204230
// 为callback函数名绑定事件
@@ -290,6 +316,31 @@ export function bindDebuggerEvents(
290316
debuggerItem.updateTime = new Date().getTime();
291317
config.persist();
292318
}
319+
320+
// 根据选择值控制URL匹配关键字输入框的禁用状态
321+
const urlPatternInput = element.querySelector(`#${debuggerInformation.id}-url-pattern-text`) as HTMLInputElement;
322+
if (urlPatternInput) {
323+
// 获取当前最新的语言设置
324+
const currentLanguage = LanguageEventManager.getInstance().getCurrentLanguage() || language;
325+
326+
if (value === 'match-all') {
327+
// 当选择"匹配所有"时,禁用输入框
328+
urlPatternInput.disabled = true;
329+
urlPatternInput.value = '';
330+
// 添加说明性的占位符文本,使用当前语言
331+
urlPatternInput.placeholder = currentLanguage.debugger_config.urlPatternMatchAllDisabledText;
332+
// 清空配置中的URL匹配关键字
333+
debuggerInformation.urlPattern = '';
334+
if (debuggerItem) {
335+
debuggerItem.urlPattern = '';
336+
config.persist();
337+
}
338+
} else {
339+
// 启用输入框并恢复原始占位符,使用当前语言
340+
urlPatternInput.disabled = false;
341+
urlPatternInput.placeholder = currentLanguage.debugger_config.urlPatternTextPlaceholder;
342+
}
343+
}
293344
}
294345
}
295346
)

src/config/ui/component/language/en.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { Language } from './types';
99
export const english: Language = {
1010
global_settings: {
1111
title: "Global Settings",
12-
language: "Interface Language:",
13-
languageTips: "You can modify the language of this configuration interface, and the changes will take effect the next time you enter!",
12+
language: "界面语言:",
13+
languageTips: "You can modify the language of this configuration interface, and the changes will take effect immediately!",
1414
flagPrefix: "Hook Flag Prefix:",
1515
flagPrefixTips: "When hooking, some globally unique flags will be set. You can customize the prefix.",
1616
flagPrefixPlaceholder: "You can customize the global prefix. If not set, the default is JSREI_js_script_hook",
@@ -29,17 +29,21 @@ export const english: Language = {
2929
enableTips: "Whether to enable this breakpoint. It will only take effect when the breakpoint is enabled. Unchecking it can temporarily disable the breakpoint without deleting it.",
3030
urlPattern: "URL Matching Method:",
3131
urlPatternTips: "The URL matching method is used to specify when the script's URL meets certain conditions to hit this breakpoint.",
32+
urlPatternKeyword: "Matching Keyword:",
3233
urlPatternTypeTips: "Specify how to match the Script URL:",
3334
urlPatternType_EqualsThisString: "The Script URL must exactly match the given string.",
3435
urlPatternType_ContainsThisString: "The Script URL contains the given string.",
3536
urlPatternType_MatchThisRegexp: "The Script URL matches the given regular expression.",
3637
urlPatternType_MatchALL: "Directly match all Script URLs.",
3738
urlPatternTextTips: "Enter a keyword or expression.",
3839
urlPatternTextPlaceholder: "Enter a keyword or expression.",
40+
urlPatternMatchAllDisabledText: "No keyword needed in \"Match All URLs\" mode",
3941
urlPatternTest: "Test",
4042
urlPatternTestTips: "You can enter a script URL to test whether this breakpoint hits it.",
4143
urlPatternTestPrompt: "Please enter the URL to test:",
4244
urlPatternTestResult: "Test Result:",
45+
urlPatternTestMatch: "✅ Match",
46+
urlPatternTestNotMatch: "❌ Not Match",
4347
enableRequestDebugger: "Enable Request Breakpoint:",
4448
enableRequestDebuggerTips: "After enabling the request breakpoint, the breakpoint will be triggered before the script request is sent.",
4549
enableResponseDebugger: "Enable Response Breakpoint:",

src/config/ui/component/language/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ export interface DebuggerConfigLanguage {
3333
enableTips: string;
3434
urlPattern: string;
3535
urlPatternTips: string;
36+
urlPatternKeyword: string;
3637
urlPatternTypeTips: string;
3738
urlPatternType_EqualsThisString: string;
3839
urlPatternType_ContainsThisString: string;
3940
urlPatternType_MatchThisRegexp: string;
4041
urlPatternType_MatchALL: string;
4142
urlPatternTextTips: string;
4243
urlPatternTextPlaceholder: string;
44+
urlPatternMatchAllDisabledText: string;
4345
urlPatternTest: string;
4446
urlPatternTestTips: string;
4547
urlPatternTestPrompt: string;
4648
urlPatternTestResult: string;
49+
urlPatternTestMatch: string;
50+
urlPatternTestNotMatch: string;
4751
enableRequestDebugger: string;
4852
enableRequestDebuggerTips: string;
4953
enableResponseDebugger: string;

src/config/ui/component/language/zh.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { Language } from './types';
99
export const chinese: Language = {
1010
global_settings: {
1111
title: "全局设置",
12-
language: "界面语言:",
13-
languageTips: "你可以修改此配置界面的语言,修改后下次进入生效! <br/> You can modify the language of this configuration interface, and the changes will take effect the next time you enter!",
12+
language: "Interface Language:",
13+
languageTips: "你可以修改此配置界面的语言,修改后立即生效! <br/> You can modify the language of this configuration interface, and the changes will take effect immediately!",
1414
flagPrefix: "Hook Flag前缀:",
1515
flagPrefixTips: "在Hook的时候会设置一些全局唯一的标志位,你可以个性化修改为自定义的前缀",
1616
flagPrefixPlaceholder: "可自定义全局前缀,未设置默认为 JSREI_js_script_hook",
@@ -29,17 +29,21 @@ export const chinese: Language = {
2929
enableTips: "是否启用此断点,仅当断点处于启用状态的时候才会生效,取消勾选可以暂时禁用断点而无需删除。",
3030
urlPattern: "URL匹配方式:",
3131
urlPatternTips: "URL匹配方式用于指定当Script的URL符合什么条件时命中此断点",
32+
urlPatternKeyword: "匹配关键字:",
3233
urlPatternTypeTips: "指定以什么方式匹配Script URL:",
3334
urlPatternType_EqualsThisString: "Script URL需要完全匹配给定的字符串",
3435
urlPatternType_ContainsThisString: "Script URL包含给定的字符串",
3536
urlPatternType_MatchThisRegexp: "Script URL匹配给定的正则表达式",
3637
urlPatternType_MatchALL: "直接匹配所有Script URL",
3738
urlPatternTextTips: "输入关键字或者表达式",
3839
urlPatternTextPlaceholder: "输入关键字或者表达式",
40+
urlPatternMatchAllDisabledText: "在\"匹配所有URL\"模式下不需要填写关键字",
3941
urlPatternTest: "测试",
4042
urlPatternTestTips: "你可以输入一个script url测试此断点对其命中情况",
4143
urlPatternTestPrompt: "请输入要测试的URL:",
4244
urlPatternTestResult: "测试结果:",
45+
urlPatternTestMatch: "✅ 匹配",
46+
urlPatternTestNotMatch: "❌ 不匹配",
4347
enableRequestDebugger: "是否开启请求断点:",
4448
enableRequestDebuggerTips: "启用请求断点后,在script请求发出之前进入断点",
4549
enableResponseDebugger: "是否开启响应断点:",

0 commit comments

Comments
 (0)