-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
23 lines (19 loc) · 925 Bytes
/
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
const shortenUrl = async () => {
const longUrl = document.getElementById('long-url').value;
const response = await fetch(`https://api.shrtco.de/v2/shorten?url=${longUrl}`);
const data = await response.json();
const shortUrl = data.result.full_short_link;
const shortUrlContainer = document.getElementById('short-url-container');
const shortUrlLink = document.getElementById('short-url').querySelector('a');
shortUrlLink.href = shortUrl;
shortUrlLink.textContent = shortUrl;
shortUrlContainer.style.display = 'block';
const copyBtn = document.getElementById('copy-btn');
copyBtn.addEventListener('click', () => {
navigator.clipboard.writeText(shortUrl).then(() => {
alert('Copied to clipboard!');
});
});
};
const shortenBtn = document.getElementById('shorten-btn');
shortenBtn.addEventListener('click', shortenUrl);