1+ const { DebuggerTester} = require ( "../debugger/debugger-tester" ) ;
2+ const { Debugger} = require ( "../debugger/debugger" ) ;
3+ const GM_config_name = "js-script-hook-config-name" ;
4+
15/**
26 * 支持的相关配置
37 */
48class Config {
59
6- /**
7- *
8- * @param urlPattern {String | RegExp} 用于与script类型的请求的URL做匹配进入断点
9- * @param callbackFunctionParamName {String} 传递jsonp回调函数名字的参数,比如 "callback"
10- */
11- constructor ( urlPattern , callbackFunctionParamName ) {
10+ constructor ( ) {
11+
12+ // 默认为英文的操作界面
13+ this . language = "english" ;
1214
1315 // 让用户能够自己指定前缀,也许会有一些拥有感?之前ast hook好像就有个哥们喜欢这样干...
1416 this . prefix = "CC11001100" ;
@@ -18,13 +20,94 @@ class Config {
1820
1921 // 是否忽略不是jsonp的请求
2022 this . isIgnoreNotJsonpRequest = true ;
23+
24+ // 在打开配置页面的时候自动跳转到项目主页
25+ this . autoJumpProjectSiteOnConfiguraion = true ;
26+
27+ // 所有的断点
28+ this . debuggers = [ ] ;
29+ }
30+
31+ findDebuggerById ( id ) {
32+ for ( let debuggerInformation of this . debuggers ) {
33+ if ( debuggerInformation . id === id ) {
34+ return debuggerInformation ;
35+ }
36+ }
37+ return null ;
38+ }
39+
40+ addDebugger ( debuggerInformation ) {
41+ // TODO 2024-12-22 05:06:15 断点的有效性校验
42+ this . debuggers . push ( debuggerInformation ) ;
43+ }
44+
45+ removeDebuggerById ( id ) {
46+ const newDebuggers = [ ] ;
47+ for ( let debuggerInformation of this . debuggers ) {
48+ if ( debuggerInformation . id !== id ) {
49+ newDebuggers . push ( debuggerInformation ) ;
50+ }
51+ }
52+ this . debuggers = newDebuggers ;
2153 }
2254
55+ load ( ) {
56+ const configJsonString = GM_getValue ( GM_config_name ) ;
57+ if ( ! configJsonString ) {
58+ return this ;
59+ }
60+ const o = JSON . parse ( configJsonString ) ;
61+ this . language = o . language ;
62+ this . prefix = o . prefix ;
63+ this . isIgnoreJsSuffixRequest = o . isIgnoreJsSuffixRequest ;
64+ this . isIgnoreNotJsonpRequest = o . isIgnoreNotJsonpRequest ;
65+ this . autoJumpProjectSiteOnConfiguraion = o . autoJumpProjectSiteOnConfiguraion ;
66+ this . debuggers = [ ] ;
67+ for ( let debuggerInformationObject of o . debuggers ) {
68+ const debuggerInformation = new Debugger ( ) ;
69+ debuggerInformation . id = debuggerInformationObject . id ;
70+ debuggerInformation . enable = debuggerInformationObject . enable ;
71+ debuggerInformation . urlPattern = debuggerInformationObject . urlPattern ;
72+ debuggerInformation . enableRequestDebugger = debuggerInformationObject . enableRequestDebugger ;
73+ debuggerInformation . enableResponseDebugger = debuggerInformationObject . enableResponseDebugger ;
74+ debuggerInformation . callbackFunctionParamName = debuggerInformationObject . callbackFunctionParamName ;
75+ debuggerInformation . comment = debuggerInformationObject . comment ;
76+ this . debuggers . push ( debuggerInformation ) ;
77+ }
78+ return this ;
79+ }
80+
81+ persist ( ) {
82+ const configJsonString = JSON . stringify ( this ) ;
83+ GM_setValue ( GM_config_name , configJsonString ) ;
84+ }
85+
86+ /**
87+ * 执行测试所有断点,看看是否有条件命中啥的
88+ *
89+ * @param scriptContext {ScriptContext}
90+ */
91+ testAll ( scriptContext ) {
92+ for ( let jsonpDebugger of this . debuggers ) {
93+ new DebuggerTester ( ) . test ( this , jsonpDebugger , scriptContext ) ;
94+ }
95+ }
96+
97+ }
98+
99+ let globalConfig = new Config ( ) ;
100+
101+ function initConfig ( ) {
102+ globalConfig . load ( ) ;
23103}
24104
25- const globalConfig = new Config ( ) ;
105+ function getGlobalConfig ( ) {
106+ return globalConfig ;
107+ }
26108
27109module . exports = {
28110 Config,
29- globalConfig
111+ initConfig,
112+ getGlobalConfig
30113}
0 commit comments