Skip to content

Commit

Permalink
Remove unnecessary hit function
Browse files Browse the repository at this point in the history
Rename shouldLog to shouldPruneResponse
  • Loading branch information
AdamWr committed Oct 10, 2022
1 parent cf1f380 commit 8185ae3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/scriptlets/xml-prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
return;
}

let shouldLog = false;
let shouldPruneResponse = true;
// eslint-disable-next-line no-console
const log = console.log.bind(console);
if (!propsToRemove) {
shouldLog = true;
// If "propsToRemove" is not defined, then response shouldn't be pruned
// but it should be logged in browser console
shouldPruneResponse = false;
}

urlToMatch = toRegExp(urlToMatch);
Expand Down Expand Up @@ -109,10 +111,9 @@ export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
if (thisArg.readyState === 4) {
const { response } = thisArg;
thisArg.removeEventListener('readystatechange', pruneResponse);
if (shouldLog) {
if (!shouldPruneResponse) {
if (isXML(response)) {
log(`URL: ${xhrURL}\n${response}`);
hit(source);
}
} else {
const prunedResponseContent = pruneXML(response);
Expand Down Expand Up @@ -147,9 +148,8 @@ export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
if (urlToMatch.test(fetchURL)) {
return realFetch.apply(this, args).then((response) => {
return response.text().then((text) => {
if (shouldLog) {
if (!shouldPruneResponse) {
if (isXML(text)) {
hit(source);
log(`URL: ${fetchURL}\n${text}`);
}
return Reflect.apply(target, thisArg, args);
Expand Down
4 changes: 2 additions & 2 deletions tests/scriptlets/xml-prune.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if (!isSupported) {
const responseMPD = await response.text();

assert.ok(responseMPD.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
assert.strictEqual(window.hit, undefined, 'should not hit');
done();
});

Expand Down Expand Up @@ -205,7 +205,7 @@ if (!isSupported) {
xhr.open(METHOD, MPD_PATH);
xhr.onload = () => {
assert.ok(xhr.responseText.indexOf('pre-roll-1-ad-1') > -1);
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
assert.strictEqual(window.hit, undefined, 'should not hit');
done();
};
xhr.send();
Expand Down
2 changes: 1 addition & 1 deletion wiki/about-scriptlets.md
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ example.org#%#//scriptlet('xml-prune'[, propsToMatch[, optionalProp[, urlToMatch
example.org#%#//scriptlet('xml-prune', 'Period[id*="-ad-"]', '', '.mpd')
```
4. Call with no arguments will log response payload at the console
4. Call with no arguments will log response payload and URL at the console
```
example.org#%#//scriptlet('xml-prune')
```
Expand Down

0 comments on commit 8185ae3

Please sign in to comment.