-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
48 lines (44 loc) · 1.77 KB
/
Copy pathcontentScript.js
File metadata and controls
48 lines (44 loc) · 1.77 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
// Listen for a message from the popup
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === "scrapeEmails") {
scrapeEmails().then(scrapedEmails => {
console.log("in listener Scraped emails:", scrapedEmails);
if (scrapedEmails.length > 0) {
chrome.runtime.sendMessage({emails: scrapedEmails});
} else {
chrome.runtime.sendMessage({message: "No emails found"});
}
});
}
});
// Scrapuu
function scrapeEmails() {
return new Promise((resolve, reject) => {
// local storage secure af async so need promise
chrome.storage.local.get("emailType", function(data) {
var emailType = data.emailType || 'all';
var emailRegex;
// in case you want a specific email extension, modify the code here
// :/[a-zA-Z0-9._-]+@gmail\.[a-zA-Z]{2,6}/g
// :/[a-zA-Z0-9._-]+@gmail\.com/g
switch (emailType) {
case 'gmail':
emailRegex = /[a-zA-Z0-9._-]+@gmail\.[a-zA-Z]{2,6}/g;
break;
case 'outlook':
emailRegex = /[a-zA-Z0-9._-]+@outlook\.[a-zA-Z]{2,6}/g;
break;
case 'hotmail':
emailRegex = /[a-zA-Z0-9._-]+@hotmail\.[a-zA-Z]{2,6}/g;
break;
default:
emailRegex = /[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}/g;
break;
}
const pageText = document.body.innerText;
const emails = pageText.match(emailRegex) || [];
console.log("in function Scraped emails:", emails);
resolve(emails);
});
});
}