-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (24 loc) · 840 Bytes
/
Copy pathscript.js
File metadata and controls
38 lines (24 loc) · 840 Bytes
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
async function shortenURL() {
const longUrl = document.getElementById("longUrl").value;
const result = document.getElementById("result");
if(longUrl === ""){
alert("Please enter a URL");
return;
}
try{
const response = await fetch(`https://tinyurl.com/api-create.php?url=${encodeURIComponent(longUrl)}`);
const shortUrl = await response.text();
result.innerHTML = `
<h3>Short URL</h3>
<a href="${shortUrl}" target="_blank">${shortUrl}</a>
<br><br>
<button onclick="copyURL('${shortUrl}')">Copy</button>
`;
}catch(error){
result.innerHTML="<p>Something went wrong!</p>";
}
}
function copyURL(url){
navigator.clipboard.writeText(url);
alert("Copied Successfully!");
}