-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline_script_9.js
More file actions
129 lines (53 loc) · 2.46 KB
/
inline_script_9.js
File metadata and controls
129 lines (53 loc) · 2.46 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
const emailsTextarea = document.getElementById('emails');
const downloadBtn = document.getElementById('download-btn');
const messageDiv = document.getElementById('message');
downloadBtn.addEventListener('click', () => {
const emailList = emailsTextarea.value.trim().split('\n');
if (!emailList.length) {
messageDiv.textContent = 'Please paste some emails first.';
return;
}
// Remove duplicate emails and non-email formats
const uniqueEmails = new Set(emailList.filter(email => {
const trimmedEmail = email.trim();
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Basic email format validation
return trimmedEmail && emailRegex.test(trimmedEmail);
}));
const originalEmailCount = uniqueEmails.size; // Count unique emails
let currentFile = 1;
let fileContent = '';
let emailsInFile = 0; // Track emails in the current file
for (const email of uniqueEmails) {
if (emailsInFile >= 1999) { // Check if current file has reached the limit
createAndDownloadFile(fileContent, currentFile);
currentFile++;
fileContent = '';
emailsInFile = 0;
}
fileContent += (fileContent ? ',' : 'Email ID') + '\n' + email; // Add header only for the first email in each file
emailsInFile++; // Increment emails in the current file
}
if (fileContent.length) {
createAndDownloadFile(fileContent, currentFile);
}
messageDiv.textContent = `Downloaded ${originalEmailCount} original emails successfully!`;
});
function createAndDownloadFile(content, fileNumber) {
// Generate random filename with prefix and suffix
const randomString = Math.random().toString(36).substring(2, 7); // Generate random 5-character alphanumeric string
const filename = `Vendor List_${randomString}`;
const blob = new Blob([content], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
}
// Update message on textarea input change
emailsTextarea.addEventListener('input', () => {
const emailList = emailsTextarea.value.trim().split('\n');
const uniqueEmails = new Set(emailList.filter(email => email.trim())); // Basic check for non-empty entries
const originalEmailCount = uniqueEmails.size;
messageDiv.textContent = `Original emails: ${originalEmailCount}`;
});