-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
25 lines (23 loc) · 1.07 KB
/
script.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
document.getElementById('gerarLink').addEventListener('click', function() {
const ddd = document.getElementById('ddd').value;
const numero = document.getElementById('numero').value;
const mensagem = encodeURIComponent(document.getElementById('mensagem').value);
if (ddd && numero && mensagem) {
const link = `https://wa.me/${ddd}${numero}?text=${mensagem}`;
document.querySelector('.text-link').innerHTML = `<p><a href="#" id="generatedLink">${link}</a></p>`;
} else {
alert('Please fill in all the required fields.');
document.querySelector('.text-link').innerHTML = '<p>Link (Click to copy)</p>';
}
});
document.querySelector('.text-link').addEventListener('click', function(event) {
if (event.target.id === 'generatedLink') {
const tempInput = document.createElement('input');
tempInput.value = event.target.textContent;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
alert('Link copied to clipboard.');
}
});