|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<title>CofURL.cut</title> |
|
<p></p> |
|
</head> |
|
<body> |
|
<h1>CofURLcut</h1> |
|
<label for="long-url">Enter a long link:</label> |
|
<p></p> |
|
<input type="text" id="long-url" placeholder="https://cofai-urlcut.hf.space"> |
|
<p></p> |
|
<button id="shorten-button">Shorten</button> |
|
<br> |
|
<p></p> |
|
<label for="short-url">Short link:</label> |
|
<p></p> |
|
<input type="text" id="short-url" readonly> |
|
<p></p> |
|
<script> |
|
document.getElementById("shorten-button").addEventListener("click", function() { |
|
var longUrl = document.getElementById("long-url").value; |
|
|
|
|
|
fetch("https://api-ssl.bitly.com/v4/shorten", { |
|
method: "POST", |
|
headers: { |
|
"Content-Type": "application/json", |
|
"Authorization": "326c6f40970f20b2e71669323f7849575789630b" |
|
}, |
|
body: JSON.stringify({ |
|
long_url: longUrl |
|
}) |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
var shortUrl = data.link; |
|
document.getElementById("short-url").value = shortUrl; |
|
}) |
|
.catch(error => { |
|
console.error(error); |
|
document.getElementById("short-url").value = "Ошибка при сокращении ссылки."; |
|
}); |
|
}); |
|
</script> |
|
<p></p> |
|
Link shortener by CofAI |
|
</body> |
|
</html> |
|
|