Created
April 8, 2022 14:53
-
-
Save aflansburg/65112ca6aacd0f7a2862ee53d229410e to your computer and use it in GitHub Desktop.
Simple Redact/Hide/Obscure/Mask text content on page with JS
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
/* Finds text content in some element and redacts it | |
with the provided mask value | |
*/ | |
function redactContent(textValue, tagType, maskValue){ | |
for (const tag of document.querySelectorAll(tagType)) { | |
if (tag.textContent.includes(textValue)) { | |
tag.textContent = maskValue; | |
}} | |
} | |
// use case: redact pricing on a page | |
// before: <span>$100.45</span> | |
// redactContent('$', 'span', 'REDACTED') | |
// after: <span>REDACTED</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment