Skip to content

Commit 8e40281

Browse files
committed
feat: 搞了下国际化,AI翻译贼拉牛逼
1 parent fafd148 commit 8e40281

File tree

4 files changed

+92
-50
lines changed

4 files changed

+92
-50
lines changed

src/config/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class Config {
1818
this.hookType = "use-proxy-function";
1919

2020
// 是否忽略.js后缀的请求
21-
this.isIgnoreJsSuffixRequest = true;
21+
this.isIgnoreJsSuffixRequest = false;
2222

2323
// 是否忽略不是jsonp的请求
24-
this.isIgnoreNotJsonpRequest = true;
24+
this.isIgnoreNotJsonpRequest = false;
2525

2626
// 在打开配置页面的时候自动跳转到项目主页
2727
this.autoJumpProjectSiteOnConfiguraion = true;

src/config/ui/component/language.js

Lines changed: 84 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
// 中文菜单
2+
const {getGlobalConfig} = require("../../config");
23
const chinese = {
34
global_settings: {
45

56
title: "全局设置",
67

78
language: "界面语言:",
8-
languageTips: "你可以修改此配置界面的语言,修改后下次进入生效!",
9+
languageTips: "你可以修改此配置界面的语言,修改后下次进入生效! <br/> You can modify the language of this configuration interface, and the changes will take effect the next time you enter!",
910

1011
flagPrefix: "Hook Flag前缀:",
1112
flagPrefixTips: "在Hook的时候会设置一些全局唯一的标志位,你可以个性化修改为自定义的前缀",
1213
flagPrefixPlaceholder: "可自定义全局前缀,未设置默认为 JSREI_js_script_hook",
1314

1415
responseDebuggerHookType: "响应断点Hook方式:",
15-
responseDebuggerHookTypeTips: "此选项刷新页面后生效",
16+
responseDebuggerHookTypeTips: "当Hook jsonp的callback函数的时候,有两种方式实现Hook:<br/><br/>一种是替换掉callback方法的引用,相当于是一个代理函数,这种需要在命中断点后再点一下跟进去callback函数的实现,这种方式兼容性比较好,绝大多数网站都可以丝滑兼容;<br/><br/>还有一种方式是直接改写callback函数的函数体,相当于是对函数的代码实现进行编辑后重新声明,这样子可以直接把断点打在callback函数体中,但此种方式可能会有一些作用域的兼容性问题,如有遇到报错,请调整为代理方式实现Hook;<br/><br/>注意,此选项修改后刷新页面后生效",
1617
responseDebuggerHookTypeUseProxyFunction: "使用代理函数实现Hook",
17-
responseDebuggerHookTypeUseRedeclareFunction: "直接修改网站callback函数体(注意可能会有作用域问题)",
18+
responseDebuggerHookTypeUseRedeclareFunction: "直接修改网站callback函数体(注意可能会有兼容性问题)",
1819

1920
isIgnoreJsSuffixRequest: "是否忽略.js后缀的请求:",
2021
isIgnoreJsSuffixRequestTips: "大多数时候.js后缀的请求都是单纯的加载JavaScript资源文件,可以选择忽略掉这类请求,当勾选的时候,控制台上也不会再打印.js请求",
@@ -23,7 +24,7 @@ const chinese = {
2324
isIgnoreNotJsonpRequestTips: "如果只关注jsonp类型的请求,可以选择忽略掉其它请求,当勾选的时候,控制台上也不会再打印非jsonp请求",
2425

2526
autoJumpProjectSiteOnConfiguraion: "跳转到项目主页打开此界面以防样式错乱:",
26-
autoJumpProjectSiteOnConfiguraionTips: "油猴脚本注入的界面可能会跟网页中原有的样式发生冲突或者污染,从而导致样式错乱,跳转到经过测试的项目主页打开设置界面可以有效防止布局错乱",
27+
autoJumpProjectSiteOnConfiguraionTips: "油猴脚本注入的界面可能会跟网页中原有的样式发生冲突或者污染,从而导致样式错乱,跳转到经过测试的项目主页打开设置界面可以有效防止布局错乱,推荐勾选此选项",
2728
},
2829
debugger_config: {
2930

@@ -64,6 +65,11 @@ const chinese = {
6465
commentPlaceholder: "好记性不如烂笔头",
6566
},
6667
console: {
68+
tableKey: "键",
69+
tableValue: "值",
70+
tableComment: "备注",
71+
titleRequest: "Script Hook 捕捉到请求",
72+
titleResponse: "Script Hook 捕捉到响应",
6773
time: "时间",
6874
requestId: "请求ID",
6975
isJsonpRequest: "是否是jsonp请求",
@@ -80,61 +86,97 @@ const chinese = {
8086

8187
// 英文菜单
8288
const english = {
83-
global_settings: {
89+
"global_settings": {
90+
91+
"title": "Global Settings",
8492

85-
title: "Global Settings",
93+
"language": "Interface Language:",
94+
"languageTips": "你可以修改此配置界面的语言,修改后下次进入生效! <br/> You can modify the language of this configuration interface, and the changes will take effect the next time you enter!",
8695

87-
language: "语言",
88-
languageTips: "语言",
96+
"flagPrefix": "Hook Flag Prefix:",
97+
"flagPrefixTips": "When hooking, some globally unique flags will be set. You can customize the prefix.",
98+
"flagPrefixPlaceholder": "You can customize the global prefix. If not set, the default is JSREI_js_script_hook.",
8999

90-
flagPrefix: "Flag前缀",
91-
flagPrefixTips: "Flag前缀",
92-
flagPrefixPlaceholder: "xxx",
100+
"responseDebuggerHookType": "Response Breakpoint Hook Method:",
101+
"responseDebuggerHookTypeTips": "When hooking the callback function of JSONP, there are two ways to implement the hook: <br/><br/> One is to replace the reference of the callback function, which acts as a proxy function. This requires stepping into the callback function implementation after hitting the breakpoint. This method has better compatibility and works smoothly on most websites. <br/><br/> The other method is to directly rewrite the function body of the callback function, which is equivalent to editing and redeclaring the function's code. This allows you to place the breakpoint directly in the callback function body, but there may be some scope compatibility issues. If you encounter errors, please switch to the proxy method. <br/><br/> Note: This option takes effect after refreshing the page.",
102+
"responseDebuggerHookTypeUseProxyFunction": "Use Proxy Function to Implement Hook",
103+
"responseDebuggerHookTypeUseRedeclareFunction": "Directly Modify the Callback Function Body (Note: There May Be Compatibility Issues)",
93104

94-
isIgnoreJsSuffixRequest: "忽略.js后缀的请求",
95-
isIgnoreJsSuffixRequestTips: "忽略.js后缀的请求",
105+
"isIgnoreJsSuffixRequest": "Ignore .js Suffix Requests:",
106+
"isIgnoreJsSuffixRequestTips": "Most of the time, requests with a .js suffix are simply loading JavaScript resource files. You can choose to ignore such requests. When checked, .js requests will not be printed on the console.",
96107

97-
isIgnoreNotJsonpRequest: "忽略不是jsonp的请求",
98-
isIgnoreNotJsonpRequestTips: "忽略不是jsonp的请求",
108+
"isIgnoreNotJsonpRequest": "Ignore Non-JSONP Requests:",
109+
"isIgnoreNotJsonpRequestTips": "If you are only concerned with JSONP-type requests, you can choose to ignore other requests. When checked, non-JSONP requests will not be printed on the console.",
99110

100-
autoJumpProjectSiteOnConfiguraion: "打开此界面时自动跳转到项目主页以防样式错乱",
101-
autoJumpProjectSiteOnConfiguraionTips: "打开此界面时自动跳转到项目主页以防样式错乱",
111+
"autoJumpProjectSiteOnConfiguraion": "Jump to the Project Homepage to Open This Interface to Prevent Style Issues:",
112+
"autoJumpProjectSiteOnConfiguraionTips": "The interface injected by the Tampermonkey script may conflict with or pollute the original styles of the webpage, causing style issues. Jumping to the tested project homepage to open the settings interface can effectively prevent layout issues. It is recommended to check this option."
102113
},
103-
debugger_config: {
104-
enable: "是否启用",
105-
enableTips: "是否启用此断点,仅当断点处于启用状态的时候才会生效,取消勾选可以暂时禁用断点而无需删除。",
114+
"debugger_config": {
106115

107-
urlPattern: "URL匹配方式",
108-
urlPatternTips: "",
116+
"debuggerTitle": "Breakpoint Configuration",
109117

110-
urlPatternTypeTips: "",
111-
urlPatternType_EqualsThisString: "Equals This String",
112-
urlPatternType_ContainsThisString: "Contains This String",
113-
urlPatternType_MatchThisRegexp: "Match This Regexp",
114-
urlPatternType_MatchALL: "Match ALL",
118+
"enable": "Enable This Breakpoint:",
119+
"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.",
115120

116-
urlPatternTextTips: "",
117-
urlPatternTextPlaceholder: "关键字或正则表达式",
121+
"urlPattern": "URL Matching Method:",
122+
"urlPatternTips": "The URL matching method is used to specify when the script's URL meets certain conditions to hit this breakpoint.",
118123

119-
urlPatternTest: "测试",
120-
urlPatternTestTips: "你可以输入一个script url测试此断点对其命中情况",
124+
"urlPatternTypeTips": "Specify how to match the Script URL:",
125+
"urlPatternType_EqualsThisString": "The Script URL must exactly match the given string.",
126+
"urlPatternType_ContainsThisString": "The Script URL contains the given string.",
127+
"urlPatternType_MatchThisRegexp": "The Script URL matches the given regular expression.",
128+
"urlPatternType_MatchALL": "Directly match all Script URLs.",
121129

122-
enableRequestDebugger: "是否启动请求断点",
123-
enableRequestDebuggerTips: "启动请求断点后,在script请求发出之前进入断点",
130+
"urlPatternTextTips": "Enter a keyword or expression.",
131+
"urlPatternTextPlaceholder": "Enter a keyword or expression.",
124132

125-
enableResponseDebugger: "是否启用响应断点",
126-
enableResponseDebuggerTips: "启动响应断点之后,在jsonp请求的回调函数中命中断点",
133+
"urlPatternTest": "Test",
134+
"urlPatternTestTips": "You can enter a script URL to test whether this breakpoint hits it.",
135+
"urlPatternTestPrompt": "Please enter the URL to test:",
136+
"urlPatternTestResult": "Test Result:",
127137

128-
callbackFunctionParamName: "jsonp回调函数参数名称",
129-
callbackFunctionParamNameTips: "",
130-
callbackFunctionParamNamePlaceholder: "",
138+
"enableRequestDebugger": "Enable Request Breakpoint:",
139+
"enableRequestDebuggerTips": "After enabling the request breakpoint, the breakpoint will be triggered before the script request is sent.",
131140

132-
comment: "备注",
133-
commentTips: "你可以输入一些备注,或者相关信息的一些上下文,以防止时间长了之后忘记。",
134-
commentPlaceholder: "好记性不如烂笔头",
141+
"enableResponseDebugger": "Enable Response Breakpoint:",
142+
"enableResponseDebuggerTips": "After enabling the response breakpoint, the breakpoint will be triggered in the callback function of the JSONP request.",
143+
144+
"callbackFunctionParamName": "JSONP Callback Function Parameter Name:",
145+
"callbackFunctionParamNameTips": "If not specified, the built-in engine will automatically infer the JSONP parameter name. If the inference fails, you can manually specify it.",
146+
"callbackFunctionParamNamePlaceholder": "If not specified, the built-in engine will automatically infer the JSONP parameter name.",
147+
148+
"comment": "Comment:",
149+
"commentTips": "You can enter some comments or contextual information to avoid forgetting it over time.",
150+
"commentPlaceholder": "A good memory is not as good as a written record."
151+
},
152+
"console": {
153+
tableKey: "key",
154+
tableValue: "value",
155+
tableComment: "comment",
156+
"titleRequest": "Script Hook Captured Request",
157+
"titleResponse": "Script Hook Captured Response",
158+
"time": "Time",
159+
"requestId": "Request ID",
160+
"isJsonpRequest": "Is JSONP Request",
161+
"hostname": "Request Hostname",
162+
"path": "Request Path",
163+
"param": "Request Parameters",
164+
"hash": "Request #hash",
165+
"paramName": "Parameter Name",
166+
"paramValue": "Parameter Value",
167+
"isJsonpCallback": "Is JSONP Callback Function",
168+
"codeLocation": "Code Location"
135169
}
136170
};
137171

172+
/**
173+
*
174+
* @return {{debugger_config: {urlPatternTest: string, urlPatternTestTips: string, enableTips: string, commentPlaceholder: string, debuggerTitle: string, enableRequestDebuggerTips: string, enableResponseDebugger: string, enableRequestDebugger: string, callbackFunctionParamName: string, urlPatternTypeTips: string, urlPatternTips: string, urlPatternType_MatchThisRegexp: string, urlPatternType_MatchALL: string, urlPatternType_EqualsThisString: string, urlPatternTextPlaceholder: string, enable: string, commentTips: string, urlPatternTextTips: string, enableResponseDebuggerTips: string, callbackFunctionParamNameTips: string, callbackFunctionParamNamePlaceholder: string, comment: string, urlPattern: string, urlPatternType_ContainsThisString: string}, global_settings: {languageTips: string, autoJumpProjectSiteOnConfiguraionTips: string, flagPrefix: string, flagPrefixTips: string, isIgnoreJsSuffixRequestTips: string, autoJumpProjectSiteOnConfiguraion: string, isIgnoreJsSuffixRequest: string, language: string, isIgnoreNotJsonpRequestTips: string, title: string, flagPrefixPlaceholder: string, isIgnoreNotJsonpRequest: string}}|{debugger_config: {urlPatternTest: string, urlPatternTestTips: string, enableTips: string, commentPlaceholder: string, enableRequestDebuggerTips: string, enableResponseDebugger: string, enableRequestDebugger: string, callbackFunctionParamName: string, urlPatternTypeTips: string, urlPatternTips: string, urlPatternType_MatchThisRegexp: string, urlPatternType_MatchALL: string, urlPatternType_EqualsThisString: string, urlPatternTextPlaceholder: string, enable: string, commentTips: string, urlPatternTextTips: string, enableResponseDebuggerTips: string, callbackFunctionParamNameTips: string, callbackFunctionParamNamePlaceholder: string, comment: string, urlPattern: string, urlPatternType_ContainsThisString: string}, global_settings: {languageTips: string, autoJumpProjectSiteOnConfiguraionTips: string, flagPrefix: string, flagPrefixTips: string, isIgnoreJsSuffixRequestTips: string, autoJumpProjectSiteOnConfiguraion: string, isIgnoreJsSuffixRequest: string, language: string, isIgnoreNotJsonpRequestTips: string, title: string, flagPrefixPlaceholder: string, isIgnoreNotJsonpRequest: string}}}
175+
*/
176+
function getLanguageByGlobalConfig() {
177+
return getLanguage(getGlobalConfig().language);
178+
}
179+
138180
/**
139181
*
140182
* @param language
@@ -153,6 +195,7 @@ function getLanguage(language) {
153195

154196
module.exports = {
155197
getLanguage,
198+
getLanguageByGlobalConfig,
156199
chinese,
157200
english
158201
}

src/formatter/request-formatter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const {genFormatArray} = require("../utils/log-util");
22
const {repeat, fillToLength} = require("../utils/string-util");
3-
const {getLanguage} = require("../config/ui/component/language");
3+
const {getLanguage, getLanguageByGlobalConfig} = require("../config/ui/component/language");
44
const {getGlobalConfig} = require("../config/config");
55
const {printStyledTable} = require("./table-formatter");
66
const {getUserCodeLocation} = require("../utils/code-util");
@@ -19,11 +19,11 @@ class RequestFormatter {
1919
const codeLocation = getUserCodeLocation();
2020

2121
const requestContext = scriptContext.requestContext;
22-
const language = getLanguage(getGlobalConfig().language);
22+
const language = getLanguageByGlobalConfig();
2323

2424
const data = [
2525
// TODO 2025-01-08 01:28:26 国际化
26-
["名称", "值", "备注"],
26+
[language.console.tableKey, language.console.tableValue, language.console.tableComment],
2727
[language.console.time, new Date().toLocaleString(), ""],
2828
[language.console.requestId, scriptContext.requestId, ""],
2929
[language.console.isJsonpRequest, scriptContext.isJsonp(), ""],

src/formatter/response-formatter.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {getLanguage, chinese} = require("../config/ui/component/language");
1+
const {getLanguage, chinese, getLanguageByGlobalConfig} = require("../config/ui/component/language");
22
const {fillToLength} = require("../utils/string-util");
33
const {genFormatArray} = require("../utils/log-util");
44
const {getGlobalConfig} = require("../config/config");
@@ -21,12 +21,11 @@ class ResponseFormatter {
2121

2222
const responseContext = scriptContext.responseContext;
2323
const requestContext = scriptContext.requestContext;
24-
// const language = getLanguage(getGlobalConfig().language);
25-
const language = chinese;
24+
const language = getLanguageByGlobalConfig();
2625

2726
const data = [
2827
// TODO 2025-01-08 01:28:26 国际化
29-
["名称", "值", "备注"],
28+
[language.console.tableKey, language.console.tableValue, language.console.tableComment],
3029
[language.console.time, new Date().toLocaleString(), ""],
3130
[language.console.requestId, scriptContext.requestId, ""],
3231
[language.console.isJsonpRequest, scriptContext.isJsonp(), ""],

0 commit comments

Comments
 (0)