Skip to content

Commit

Permalink
Minor code review of scriptlets
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Sep 22, 2023
1 parent 3f3f383 commit cce3f3e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions assets/resources/scriptlets.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -3711,8 +3720,7 @@ function trustedReplaceXhrResponse(
`\n\treplacement: ${replacement}`,
);
}
xhrDetails.response = textAfter;
return textAfter;
return (xhrDetails.response = textAfter);
}
get responseText() {
const response = this.response;
Expand Down

0 comments on commit cce3f3e

Please sign in to comment.