-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
45 lines (37 loc) · 1.77 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
document.addEventListener('DOMContentLoaded', function() {
// Add event listener for the "Generate Links" button
document.getElementById('generate').addEventListener('click', function() {
const contacts = document.getElementById('contacts').value.split(',');
const messageText = document.getElementById('message').value;
const encodedMessage = encodeURIComponent(messageText);
const linksDiv = document.getElementById('links');
linksDiv.innerHTML = '';
const links = [];
contacts.forEach(contact => {
const trimmedContact = contact.trim();
const link = `https://wa.me/91${trimmedContact}?text=${encodedMessage}`;
links.push(link);
const linkElement = document.createElement('a');
linkElement.href = link;
linkElement.target = '_blank'; // Opens the link in a new tab
linkElement.textContent = link;
linksDiv.appendChild(linkElement);
linksDiv.appendChild(document.createElement('br'));
});
// Store links in local storage for later use
chrome.storage.local.set({ links: links }, function() {
// Show the "Open All Links" button after storing links
document.getElementById('openAll').style.display = 'block';
});
});
// Add event listener for the "Open All Links" button
document.getElementById('openAll').addEventListener('click', function() {
// Retrieve links from local storage and open them
chrome.storage.local.get(['links'], function(result) {
const links = result.links || [];
links.forEach(link => {
chrome.tabs.create({ url: link });
});
});
});
});