@@ -59,20 +59,26 @@ <h4 class="card-header">
5959 />
6060 < label for ="instance-filter-dropdown "> Found Instances:</ label >
6161 < select id ="instance-filter-dropdown ">
62- < option value =""> </ option >
62+ < option value =""> All Instances </ option >
6363 </ select >
6464 </ div >
6565 </ div >
6666 < div class ="row ">
6767 < div class ="col-sm-10 ">
68- < label for ="blacklist-ids-incoming " style ="width: 80px "
69- > Blacklist Methods</ label
68+ < div style ="display: inline-block; margin-right: 10px; ">
69+ < select id ="filter-mode " style ="padding: 3px; ">
70+ < option value ="blacklist "> Blacklist</ option >
71+ < option value ="whitelist "> Whitelist</ option >
72+ </ select >
73+ </ div >
74+ < label for ="method-filter-ids " id ="filter-label " style ="width: 80px "
75+ > Methods</ label
7076 >
7177 < input
7278 type ="text "
73- id ="blacklist-ids-incoming "
79+ id ="method-filter-ids "
7480 placeholder ="5026,1601,1103,... "
75- style ="width: calc(100% - 83px ) "
81+ style ="width: calc(100% - 200px ) "
7682 />
7783 </ div >
7884 < div class ="col-sm-2 ">
@@ -126,12 +132,33 @@ <h5 class="modal-title">
126132 </ div >
127133 < div class ="modal-body ">
128134 < p > Method name: < span class ="method-name "> </ span > </ p >
129- < p > Incoming data:</ p >
135+ < p > Request data (Sent to server) :</ p >
130136 < pre class ="method-data-incoming "> </ pre >
131- < p > Outgoing data:</ p >
137+ < p > Response data (Received from server) :</ p >
132138 < pre class ="method-data-outgoing "> </ pre >
133139 </ div >
134140 < div class ="modal-footer ">
141+ < button
142+ type ="button "
143+ class ="btn btn-primary "
144+ id ="download-incoming-json "
145+ >
146+ < i class ="fas fa-download "> </ i > Download Request
147+ </ button >
148+ < button
149+ type ="button "
150+ class ="btn btn-primary "
151+ id ="download-outgoing-json "
152+ >
153+ < i class ="fas fa-download "> </ i > Download Response
154+ </ button >
155+ < button
156+ type ="button "
157+ class ="btn btn-success "
158+ id ="download-combined-json "
159+ >
160+ < i class ="fas fa-download "> </ i > Download Both
161+ </ button >
135162 < button
136163 type ="button "
137164 class ="btn btn-secondary "
@@ -182,7 +209,8 @@ <h5 class="modal-title">
182209 let messages = [ ] ;
183210 let foundInstances = [ ] ;
184211 let instanceFilter = "" ;
185- let incomingBlacklistIds = [ ] ;
212+ let methodFilterIds = [ ] ;
213+ let filterMode = "blacklist" ;
186214 incoming . on ( "protos" , function ( data ) {
187215 if ( foundInstances . indexOf ( data . identifier ) === - 1 ) {
188216 foundInstances . push ( data . identifier ) ;
@@ -191,11 +219,16 @@ <h5 class="modal-title">
191219 if ( STATE !== 1 ) {
192220 return ;
193221 }
194- if ( instanceFilter == "" || data . identifier !== instanceFilter ) {
222+ if ( instanceFilter ! == "" && data . identifier !== instanceFilter ) {
195223 return ;
196224 }
197- if ( incomingBlacklistIds . length > 0 ) {
198- if ( incomingBlacklistIds . indexOf ( data . methodId ) !== - 1 ) {
225+ if ( methodFilterIds . length > 0 ) {
226+ const methodIdNum = parseInt ( data . methodId ) ;
227+ const isInList = methodFilterIds . indexOf ( methodIdNum ) !== - 1 ;
228+ if ( filterMode === "blacklist" && isInList ) {
229+ return ;
230+ }
231+ if ( filterMode === "whitelist" && ! isInList ) {
199232 return ;
200233 }
201234 }
@@ -239,12 +272,17 @@ <h5 class="modal-title">
239272 if ( STATE !== 1 ) {
240273 return ;
241274 }
242- if ( incomingBlacklistIds . length > 0 ) {
243- if ( incomingBlacklistIds . indexOf ( data . methodId ) !== - 1 ) {
275+ if ( methodFilterIds . length > 0 ) {
276+ const methodIdNum = parseInt ( data . methodId ) ;
277+ const isInList = methodFilterIds . indexOf ( methodIdNum ) !== - 1 ;
278+ if ( filterMode === "blacklist" && isInList ) {
279+ return ;
280+ }
281+ if ( filterMode === "whitelist" && ! isInList ) {
244282 return ;
245283 }
246284 }
247- if ( instanceFilter == "" || data . identifier !== instanceFilter ) {
285+ if ( instanceFilter ! == "" && data . identifier !== instanceFilter ) {
248286 return ;
249287 }
250288 if ( typeof data . error !== "undefined" ) {
@@ -264,9 +302,11 @@ <h5 class="modal-title">
264302 ) ;
265303 }
266304 } ) ;
305+ let currentModalMessage = null ;
267306 $ ( "#data_socket tbody" ) . on ( "click" , "tr" , function ( ) {
268307 const message = messages . filter ( ( msg ) => msg . id == $ ( this ) [ 0 ] . id ) [ 0 ] ;
269308 if ( message == null ) return ;
309+ currentModalMessage = message ;
270310 $ ( "#modal-detail" ) . find ( ".method-id" ) . html ( message . methodId ) ;
271311 $ ( "#modal-detail" ) . find ( ".method-name" ) . html ( message . methodName ) ;
272312 $ ( "#modal-detail" )
@@ -277,6 +317,47 @@ <h5 class="modal-title">
277317 . jsonViewer ( message . response . data ) ;
278318 $ ( "#modal-detail" ) . modal ( ) ;
279319 } ) ;
320+ function downloadJSON ( data , filename ) {
321+ const jsonStr = JSON . stringify ( data , null , 2 ) ;
322+ const blob = new Blob ( [ jsonStr ] , { type : "application/json" } ) ;
323+ const url = URL . createObjectURL ( blob ) ;
324+ const a = document . createElement ( "a" ) ;
325+ a . href = url ;
326+ a . download = filename ;
327+ document . body . appendChild ( a ) ;
328+ a . click ( ) ;
329+ document . body . removeChild ( a ) ;
330+ URL . revokeObjectURL ( url ) ;
331+ }
332+
333+ $ ( "#download-incoming-json" ) . click ( function ( ) {
334+ if ( ! currentModalMessage ) return ;
335+ const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, "-" ) ;
336+ const filename = `request_${ currentModalMessage . methodName } _${ currentModalMessage . methodId } _${ timestamp } .json` ;
337+ downloadJSON ( currentModalMessage . data , filename ) ;
338+ } ) ;
339+
340+ $ ( "#download-outgoing-json" ) . click ( function ( ) {
341+ if ( ! currentModalMessage || ! currentModalMessage . response ) return ;
342+ const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, "-" ) ;
343+ const filename = `response_${ currentModalMessage . methodName } _${ currentModalMessage . methodId } _${ timestamp } .json` ;
344+ downloadJSON ( currentModalMessage . response . data , filename ) ;
345+ } ) ;
346+
347+ $ ( "#download-combined-json" ) . click ( function ( ) {
348+ if ( ! currentModalMessage ) return ;
349+ const timestamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, "-" ) ;
350+ const filename = `combined_${ currentModalMessage . methodName } _${ currentModalMessage . methodId } _${ timestamp } .json` ;
351+ const combinedData = {
352+ identifier : currentModalMessage . identifier ,
353+ methodId : currentModalMessage . methodId ,
354+ methodName : currentModalMessage . methodName ,
355+ request : currentModalMessage . data ,
356+ response : currentModalMessage . response ? currentModalMessage . response . data : null
357+ } ;
358+ downloadJSON ( combinedData , filename ) ;
359+ } ) ;
360+
280361 $ ( "#darkmode-button" ) . click ( function ( ) {
281362 if ( document . body . classList . contains ( "dark" ) ) {
282363 document . body . classList . remove ( "dark" ) ;
@@ -392,8 +473,8 @@ <h5 class="modal-title">
392473 instanceFilter = $ ( this ) . val ( ) ;
393474 storeSettings ( ) ;
394475 } ) ;
395- $ ( "#blacklist-ids-incoming " ) . keyup ( function ( ) {
396- incomingBlacklistIds =
476+ $ ( "#method-filter-ids " ) . keyup ( function ( ) {
477+ methodFilterIds =
397478 $ ( this ) . val ( ) === ""
398479 ? [ ]
399480 : $ ( this )
@@ -402,6 +483,12 @@ <h5 class="modal-title">
402483 . map ( ( x ) => parseInt ( x ) ) ;
403484 storeSettings ( ) ;
404485 } ) ;
486+
487+ $ ( "#filter-mode" ) . change ( function ( ) {
488+ filterMode = $ ( this ) . val ( ) ;
489+ clearTable ( ) ;
490+ storeSettings ( ) ;
491+ } ) ;
405492 $ ( "#maxlogs" ) . on ( "change" , function ( ) {
406493 if ( this . value == "Other" ) {
407494 let val = prompt ( "Please enter the value" , "" ) ;
@@ -418,8 +505,16 @@ <h5 class="modal-title">
418505 if ( settingsJson !== null ) {
419506 const settings = JSON . parse ( settingsJson ) ;
420507 ( STATE = parseInt ( settings [ "STATE" ] ) ) ,
421- ( instanceFilter = settings [ "instanceFilter" ] ) ,
422- ( incomingBlacklistIds = settings [ "incomingBlacklistIds" ] ) ;
508+ ( instanceFilter = settings [ "instanceFilter" ] ) ;
509+ // Handle legacy blacklist settings
510+ if ( settings [ "incomingBlacklistIds" ] ) {
511+ methodFilterIds = settings [ "incomingBlacklistIds" ] ;
512+ } else if ( settings [ "methodFilterIds" ] ) {
513+ methodFilterIds = settings [ "methodFilterIds" ] ;
514+ }
515+ if ( settings [ "filterMode" ] ) {
516+ filterMode = settings [ "filterMode" ] ;
517+ }
423518 if ( settings [ "maxLogs" ] != null && ! isNaN ( parseInt ( maxLogs ) ) ) {
424519 setLogValue ( parseInt ( settings [ "maxLogs" ] ) ) ;
425520 }
@@ -431,7 +526,8 @@ <h5 class="modal-title">
431526 $ ( "#play-button" ) . click ( ) ;
432527 }
433528 $ ( "#instance-filter" ) . val ( instanceFilter ) ;
434- $ ( "#blacklist-ids-incoming" ) . val ( incomingBlacklistIds . join ( "," ) ) ;
529+ $ ( "#method-filter-ids" ) . val ( methodFilterIds . join ( "," ) ) ;
530+ $ ( "#filter-mode" ) . val ( filterMode ) ;
435531 }
436532 $ ( "#maxlogs" ) . val ( maxLogs ) ;
437533 }
@@ -442,7 +538,8 @@ <h5 class="modal-title">
442538 JSON . stringify ( {
443539 STATE : STATE ,
444540 instanceFilter : instanceFilter ,
445- incomingBlacklistIds : incomingBlacklistIds ,
541+ methodFilterIds : methodFilterIds ,
542+ filterMode : filterMode ,
446543 maxLogs : maxLogs ,
447544 darkMode : darkMode
448545 } )
0 commit comments