-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredactor.js
32 lines (26 loc) · 1.14 KB
/
redactor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let actionRedact = function() {
const redactedOutput = '████';
let originalText = document.querySelector('.unredacted-container textarea').value; // original content to be redacted
let contentToRedact = document.querySelector('.to-redact'); // words to redact from original content
let contentToRedactValue = contentToRedact.value;
contentToRedact.focus();
// prepare content for redacting
let redactList = contentToRedactValue.split(/[\W]+/);
let redactOriginalList = originalText.trim().split(/[\W]+/);
// redact original content
redactList.forEach(function(redactWord) {
redactOriginalList.forEach(function(originalWord, i) {
if ( originalWord && redactWord.trim().toLowerCase() === originalWord.toLowerCase() ) {
redactOriginalList.splice(i, 1, redactedOutput);
}
});
});
// prepare and output redacted content
let redactedText = redactOriginalList.join(' ');
redactedText = redactedText.replace(/█ █/g, '███');
document.querySelector('.redacted-container textarea').innerText = redactedText;
};
actionRedact();
// TODO
// comma seperated terms
// one click copy redacted output