-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
103 lines (89 loc) · 3.41 KB
/
popup.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
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 obfuscateText = (text) => {
// Obfuscate email addresses
let obfuscated = text.replace(
/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/g,
(match) => {
return match.replace(/./g, "*"); // Simple obfuscation
}
);
// Obfuscate phone numbers (US format, for simplicity)
obfuscated = obfuscated.replace(
/\+?\d{1,4}[\s-]?\(?\d{1,4}\)?[\s-]?\d{1,4}[\s-]?\d{1,9}/g,
(match) => {
return match.replace(/\d/g, "*"); // Simple obfuscation
}
);
// Obfuscate credit card numbers (simple pattern)
obfuscated = obfuscated.replace(/\b(?:\d[ -]*?){13,16}\b/g, (match) => {
return match.replace(/\d/g, "*"); // Simple obfuscation
});
// Obfuscate Social Security Numbers (SSN)
obfuscated = obfuscated.replace(/\b\d{3}-\d{2}-\d{4}\b/g, (match) => {
return match.replace(/\d/g, "*"); // Simple obfuscation
});
// Obfuscate URLs
obfuscated = obfuscated.replace(
/\bhttps?:\/\/[^\s/$.?#].[^\s]*\b/g,
(match) => {
return match.replace(/./g, "*"); // Simple obfuscation
}
);
// Obfuscate IP addresses
obfuscated = obfuscated.replace(/\b(?:\d{1,3}\.){3}\d{1,3}\b/g, (match) => {
return match.replace(/\d/g, "*"); // Simple obfuscation
});
// Obfuscate dates (simple format YYYY-MM-DD, MM/DD/YYYY)
obfuscated = obfuscated.replace(
/\b(?:\d{4}[-/]\d{2}[-/]\d{2}|\d{2}[-/]\d{2}[-/]\d{4})\b/g,
(match) => {
return match.replace(/\d/g, "*"); // Simple obfuscation
}
);
return obfuscated;
};
document.getElementById("obfuscateButton").addEventListener("click", () => {
const inputText = document.getElementById("inputText").value;
const obfuscatedText = advancedObfuscateText(obfuscateText(inputText));
document.getElementById("inputText").value = obfuscatedText;
document.getElementById("copyButton").disabled = false; // Enable copy button
document.getElementById("status").classList.remove("show"); // Hide status initially
});
document.getElementById("copyButton").addEventListener("click", () => {
const inputTextArea = document.getElementById("inputText");
inputTextArea.select();
document.execCommand("copy");
// Show status message
document.getElementById("status").classList.add("show");
// Disable copy button
document.getElementById("copyButton").disabled = true;
});
const advancedObfuscateText = (text) => {
// Obfuscate email addresses
const obfuscateEmail = (email) => {
const [localPart, domain] = email.split("@");
const obfuscatedLocalPart =
localPart.slice(0, 2) + "*".repeat(localPart.length - 2);
return `${obfuscatedLocalPart}@${domain}`;
};
// Obfuscate phone numbers
const obfuscatePhoneNumber = (phoneNumber) => {
return phoneNumber.replace(/\d(?=\d{4})/g, "*");
};
// Obfuscate names (assuming names are capitalized words)
const obfuscateName = (name) => {
return name.charAt(0) + "*".repeat(name.length - 1);
};
// Obfuscate place names (assuming place names are capitalized words)
const obfuscatePlaceName = (placeName) => {
return placeName.charAt(0) + "*".repeat(placeName.length - 1);
};
// Replace email addresses, phone numbers, names, and place names in the text
return text
.replace(
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
obfuscateEmail
)
.replace(/\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b/g, obfuscatePhoneNumber)
.replace(/\b[A-Z][a-z]*\b/g, obfuscateName)
.replace(/\b[A-Z][a-z]*\b/g, obfuscatePlaceName);
};