From cce3f3efc180747bc5ca9e391a91dea464575eb1 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 22 Sep 2023 09:33:02 -0400 Subject: [PATCH] Minor code review of scriptlets --- assets/resources/scriptlets.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 0bfb7a8c4850f..aecae66d8a0fe 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -1365,9 +1365,12 @@ function jsonPruneXhrResponse( if ( xhrDetails === undefined ) { return innerResponse; } - if ( xhrDetails.latestResponseLength != innerResponse.length ) { + const responseLength = typeof innerResponse === 'string' + ? innerResponse.length + : undefined; + if ( xhrDetails.lastResponseLength !== responseLength ) { xhrDetails.response = undefined; - xhrDetails.latestResponseLength = innerResponse.length; + xhrDetails.lastResponseLength = responseLength; } if ( xhrDetails.response !== undefined ) { return xhrDetails.response; @@ -3694,12 +3697,18 @@ function trustedReplaceXhrResponse( if ( xhrDetails === undefined ) { return innerResponse; } - if ( typeof innerResponse !== 'string' ) { - xhrDetails.response = innerResponse; + const responseLength = typeof innerResponse === 'string' + ? innerResponse.length + : undefined; + if ( xhrDetails.lastResponseLength !== responseLength ) { + xhrDetails.response = undefined; + xhrDetails.lastResponseLength = responseLength; } - let outerResponse = xhrDetails.response; - if ( outerResponse !== undefined ) { - return outerResponse; + if ( xhrDetails.response !== undefined ) { + return xhrDetails.response; + } + if ( typeof innerResponse !== 'string' ) { + return (xhrDetails.response = innerResponse); } const textBefore = innerResponse; const textAfter = textBefore.replace(rePattern, replacement); @@ -3711,8 +3720,7 @@ function trustedReplaceXhrResponse( `\n\treplacement: ${replacement}`, ); } - xhrDetails.response = textAfter; - return textAfter; + return (xhrDetails.response = textAfter); } get responseText() { const response = this.response;