-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
106 lines (70 loc) · 2.78 KB
/
app.js
File metadata and controls
106 lines (70 loc) · 2.78 KB
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
const inputedWords = document.getElementById("words")
const advanceOptionToggle = document.querySelector(".advance-toggle")
const advanceOptionArrow = document.getElementById("advance-option_arrow")
const advanceOption = document.querySelector(".advance-options")
const replaceWith = document.getElementById("replace-with")
const caseSensitivity = document.getElementById("case-sensitivity")
const text = document.getElementById("text")
const redact = document.getElementById("redact")
const stats = document.querySelector(".stats")
advanceOptionToggle.addEventListener("click", advanceToggleHandler)
redact.addEventListener("click", redactHandler)
function advanceToggleHandler() {
if (advanceOption.style.height !== "5rem") {
advanceOption.style.height = "5rem";
advanceOption.style.padding = "0.3rem"
advanceOptionArrow.innerHTML = "▲"
} else if (advanceOption.style.height == "5rem" ) {
advanceOption.style.height = "0"
advanceOption.style.padding = "0 0.3rem"
advanceOptionArrow.innerHTML = "▼"
}
}
function redactHandler() {
startTime = performance.now()
if (inputedWords.value.trim()) {
wordsToReplace = inputedWords.value.split(",")
} else {
alert("enter word you want to replace")
return
}
if (text.value.trim()) {
textToReplace = text.value.trim()
} else {
alert("enter text to scramble")
return
}
if (replaceWith.value.trim()) {
wordToReplaceWith = replaceWith.value.trim()
} else {
wordToReplaceWith = "****"
}
if (caseSensitivity.checked) {
__caseSensitivity = "g"
} else {
__caseSensitivity = "ig"
}
wordsScanned = text.value.split(" ").length
totalWordScrambled = 0
totalChracterScrambled = 0
wordsToReplace.forEach(word => {
wordReg = new RegExp(`(?<![a-z])${word.trim()}(?![a-z])`, __caseSensitivity )
if (textToReplace.match(wordReg)) {
wordScrambled = textToReplace.match(wordReg).length
chracterScrambled = wordScrambled * word.trim().length
totalWordScrambled += wordScrambled * word.split(" ").length
totalChracterScrambled += chracterScrambled
}
textToReplace = textToReplace.replace(wordReg, wordToReplaceWith)
text.value = textToReplace.trim()
});
endTime = performance.now()
timeTaken = (endTime - startTime).toFixed(4)
console.log(wordsScanned, totalWordScrambled, totalChracterScrambled, timeTaken)
stats.innerText = `Words scaned: ${wordsScanned}
Words scrambled: ${totalWordScrambled}
Character scrambled: ${totalChracterScrambled}
Time: ${timeTaken} ms
`
window.scrollBy(0, 100);
}