Get it here:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Shortener</title>
<style>
/* CSS styles for the URL Shortener */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}
input[type="text"],
input[type="submit"] {
width: 100%;
padding: 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid #ccc;
}
input[type="submit"] {
background-color: #4caf50;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.result {
margin-top: 20px;
padding: 10px;
border-radius: 5px;
background-color: #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.result a {
color: #4caf50;
text-decoration: none;
font-weight: bold;
}
@media (max-width: 600px) {
/* Responsive styles for smaller screens */
.container {
padding: 10px;
}
input[type="text"],
input[type="submit"] {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>URL Shortener</h1>
<div class="form-group">
<label for="originalUrl">Enter the URL to shorten:</label>
<input type="text" id="originalUrl" placeholder="Enter URL">
</div>
<div class="form-group">
<input type="submit" value="Shorten" onclick="shortenUrl()">
</div>
<div id="result" class="result"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
// JavaScript code for the URL Shortener
function shortenUrl() {
var originalUrl = document.getElementById("originalUrl").value;
var resultDiv = document.getElementById("result");
// Clear previous results
resultDiv.innerHTML = "";
// Send AJAX request using Axios
axios.get("https://api.shrtco.de/v2/shorten?url=" + encodeURIComponent(originalUrl))
.then(function(response) {
var data = response.data;
if (data.ok) {
var shortUrl = data.result.full_short_link;
resultDiv.innerHTML = "<p><strong>Shortened URL:</strong> <a href='" + shortUrl + "' target='_blank'>" + shortUrl + "</a></p>";
} else {
resultDiv.innerHTML = "<p style='color: red;'>Error occurred while shortening the URL.</p>";
}
})
.catch(function(error) {
resultDiv.innerHTML = "<p style='color: red;'>Error occurred while shortening the URL.</p>";
});
}
</script>
</body>
</html>