-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredact.html
121 lines (107 loc) · 3.8 KB
/
redact.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<style>
.input-group { margin-top: 10px; }
body {
font-family: Arial;
display: flex;
flex-direction: column;
height: 100vh;
margin: 0;
}
textarea {
min-height: 200px;
margin: 0.5em;
resize: vertical;
overflow: auto;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
footer {
padding: 10px;
text-align: center;
background-color: #f2f2f2;
}
</style>
</head>
<body>
<div id="app">
<h2>Redaction App</h2>
<p><b>Usage Guide:</b> Paste your text in the input box below and click the "Redact" button. The redacted version of your text will appear in the second box. This tool attempts to redact email addresses and also replaces any text you specify in the "Custom Redaction" fields.</p>
<p>Paste your text below:</p>
<textarea v-model="inputText" rows="10" style="width: 100%;"></textarea>
<p>Email Redaction Replacement:</p>
<input v-model="emailReplacement" type="text" style="width: 100%;">
<div v-for="(redaction, index) in redactions" :key="index" class="input-group">
<input v-model="redaction.find" type="text" placeholder="Text to redact" style="width: 100%;">
<input v-model="redaction.replace" type="text" placeholder="Replacement text" style="width: 100%; margin-top: 10px;">
<input v-model="redaction.caseSensitive" type="checkbox" style="margin-top: 10px;"> Case Sensitive
<button @click="removeRedaction(index)" style="margin-top: 10px;">-</button>
</div>
<button @click="addRedaction" style="margin-top: 10px;">+ Add More Redaction</button>
<button @click="redact" style="margin-top: 10px;">Redact</button>
<p>Redacted text:</p>
<textarea v-model="redactedText" rows="10" style="width: 100%;"></textarea>
<p>Total replacements made: {{totalReplacements}}</p>
</div>
<footer style="margin-top: 20px; border-top: 1px solid #ddd; padding-top: 10px;">
<p>Note: This tool runs entirely in your browser. No data you enter here is sent to a server or shared in any way.</p>
</footer>
<script>
new Vue({
el: '#app',
data: {
inputText: '',
redactedText: '',
emailReplacement: 'user@contoso.com',
redactions: [{ find: '', replace: '', caseSensitive: false }],
totalReplacements: 0,
},
methods: {
addRedaction() {
this.redactions.push({ find: '', replace: '', caseSensitive: false });
},
removeRedaction(index) {
this.redactions.splice(index, 1);
},
redact() {
let text = this.inputText;
let totalReplacements = 0;
// Email Redaction
const emailRegex = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/gi;
const matchedEmails = text.match(emailRegex);
if (matchedEmails) {
totalReplacements += matchedEmails.length;
text = text.replace(emailRegex, this.emailReplacement);
}
// Custom Redaction
this.redactions.forEach(({ find, replace, caseSensitive }) => {
if (find !== '') {
const customRegex = new RegExp(find, caseSensitive ? '' : 'gi');
const matchedCustoms = text.match(customRegex);
if (matchedCustoms) {
totalReplacements += matchedCustoms.length;
text = text.replace(customRegex, replace);
}
}
});
this.redactedText = text;
this.totalReplacements = totalReplacements;
},
},
});
</script>
</body>
</html>