File tree Expand file tree Collapse file tree 5 files changed +37
-7
lines changed
Expand file tree Collapse file tree 5 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,6 @@ class GlobalOptionsComponent {
148148
149149 // 在打开配置页面的时候自动跳转项目主页
150150 component . find ( "#js-script-hook-global-config-autoJumpProjectSiteOnConfiguraion" ) . on ( "change" , function ( ) {
151- debugger ;
152151 getGlobalConfig ( ) . autoJumpProjectSiteOnConfiguraion = $ ( this ) . is ( ':checked' ) ;
153152 getGlobalConfig ( ) . persist ( ) ;
154153 } ) ;
Original file line number Diff line number Diff line change @@ -12,10 +12,10 @@ const chinese = {
1212 flagPrefixPlaceholder : "可自定义全局前缀,未设置默认为 CC11001100_js_script_hook" ,
1313
1414 isIgnoreJsSuffixRequest : "是否忽略.js后缀的请求:" ,
15- isIgnoreJsSuffixRequestTips : "大多数时候.js后缀的请求都是单纯的加载JavaScript资源文件,可以选择忽略掉这类请求" ,
15+ isIgnoreJsSuffixRequestTips : "大多数时候.js后缀的请求都是单纯的加载JavaScript资源文件,可以选择忽略掉这类请求,当勾选的时候,控制台上也不会再打印.js请求 " ,
1616
1717 isIgnoreNotJsonpRequest : "是否忽略不是jsonp的请求:" ,
18- isIgnoreNotJsonpRequestTips : "如果只关注jsonp类型的请求,可以选择忽略掉其它请求" ,
18+ isIgnoreNotJsonpRequestTips : "如果只关注jsonp类型的请求,可以选择忽略掉其它请求,当勾选的时候,控制台上也不会再打印非jsonp请求 " ,
1919
2020 autoJumpProjectSiteOnConfiguraion : "跳转到项目主页打开此界面以防样式错乱:" ,
2121 autoJumpProjectSiteOnConfiguraionTips : "油猴脚本注入的界面可能会跟网页中原有的样式发生冲突或者污染,从而导致样式错乱,跳转到经过测试的项目主页打开设置界面可以有效防止布局错乱" ,
Original file line number Diff line number Diff line change @@ -165,6 +165,28 @@ class DebuggerTester {
165165 return true ;
166166 }
167167
168+ /**
169+ * 判断是否需要打印到控制台上
170+ *
171+ * @param globalConfig
172+ * @param scriptContext
173+ * @return {boolean }
174+ */
175+ isNeedPrintToConsole ( globalConfig , scriptContext ) {
176+
177+ // 忽略js文件请求
178+ if ( globalConfig . isIgnoreJsSuffixRequest && scriptContext . isJsSuffixRequest ( ) ) {
179+ return false ;
180+ }
181+
182+ // 忽略不是jsonp的请求
183+ if ( globalConfig . isIgnoreNotJsonpRequest && ! scriptContext . isJsonp ( ) ) {
184+ return false ;
185+ }
186+
187+ return true ;
188+ }
189+
168190}
169191
170192module . exports = {
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ const {ObjectFunctionHook} = require("./object-function-hook");
33const { ResponseContext} = require ( "../context/response/response-context" ) ;
44const { ResponseFormatter} = require ( "../formatter/response-formatter" ) ;
55const { getGlobalConfig} = require ( "../config/config" ) ;
6+ const { DebuggerTester} = require ( "../debugger/debugger-tester" ) ;
7+ const { RequestFormatter} = require ( "../formatter/request-formatter" ) ;
68
79/**
810 * 给JSONP的回调函数增加hook
@@ -44,8 +46,12 @@ class JsonpCallbackHook {
4446 new ObjectFunctionHook ( getUnsafeWindow ( ) , jsonpCallbackFunctionName ) . addHook ( function ( ) {
4547
4648 const responseContext = _this . scriptContext . responseContext = new ResponseContext ( "" , arguments ) ;
47- const s = new ResponseFormatter ( ) . format ( _this . scriptContext ) ;
48- console . log ( s ) ;
49+
50+ // 只在有必要的情况下打印
51+ if ( new DebuggerTester ( ) . isNeedPrintToConsole ( getGlobalConfig ( ) , _this . scriptContext ) ) {
52+ const s = new ResponseFormatter ( ) . format ( _this . scriptContext ) ;
53+ console . log ( s ) ;
54+ }
4955
5056 const hitDebuggers = getGlobalConfig ( ) . testAllForResponse ( _this . scriptContext ) ;
5157 } ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const {ResponseContext} = require("../context/response/response-context");
1111const { ResponseFormatter} = require ( "../formatter/response-formatter" ) ;
1212const { JsonpCallbackHook} = require ( "./jsonp-callback-hook" ) ;
1313const { formatScriptSrcToUrl} = require ( "../utils/url-util" ) ;
14+ const { DebuggerTester} = require ( "../debugger/debugger-tester" ) ;
1415
1516/**
1617 * 用于给script添加Hook
@@ -48,8 +49,10 @@ class ScriptHook {
4849 requestAnalyzer . analyze ( requestContext ) ;
4950
5051 // 在请求发送之前测试断点
51- const requestFormatter = new RequestFormatter ( ) ;
52- console . log ( requestFormatter . format ( scriptContext ) ) ;
52+ if ( new DebuggerTester ( ) . isNeedPrintToConsole ( getGlobalConfig ( ) , scriptContext ) ) {
53+ const requestFormatter = new RequestFormatter ( ) ;
54+ console . log ( requestFormatter . format ( scriptContext ) ) ;
55+ }
5356
5457 const hitDebuggers = getGlobalConfig ( ) . testAll ( scriptContext ) ;
5558 new JsonpCallbackHook ( scriptContext , hitDebuggers ) . addHook ( ) ;
You can’t perform that action at this time.
0 commit comments