This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2020 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
(function() { | ||
const $<prunePaths> = ['playerResponse.adPlacements', 'playerResponse.playerAds', 'adPlacements', 'playerAds']; | ||
const $<findOwner> = function(root, path) { | ||
let owner = root; | ||
let chain = path; | ||
while(true) { | ||
if (owner instanceof Object === false) { return; } | ||
const pos = chain.indexOf('.'); | ||
if (pos === -1) { | ||
return owner.hasOwnProperty(chain)? [owner, chain]: undefined; | ||
} | ||
const prop = chain.slice(0, pos); | ||
if (owner.hasOwnProperty(prop) === false) { return; } | ||
owner = owner[prop]; | ||
chain = chain.slice(pos + 1); | ||
} | ||
}; | ||
|
||
JSON.parse = new Proxy(JSON.parse, { | ||
apply: function() { | ||
const r = Reflect.apply(...arguments); | ||
for (const path of $<prunePaths>) { | ||
const details = $<findOwner>(r, path); | ||
if (details !== undefined) { | ||
delete details[0][details[1]]; | ||
} | ||
} | ||
return r; | ||
}, | ||
}); | ||
})(); |