This commit is contained in:
2024-08-29 19:05:53 +05:30
commit 6073a08a6d
24 changed files with 1436 additions and 0 deletions

38
script.js Normal file
View File

@@ -0,0 +1,38 @@
const form = document.querySelector(".wrapper form"),
fullURL = form.querySelector("input"),
shortenBtn = form.querySelector("form button"),
urlsArea = document.querySelector(".urls-area");
form.onsubmit = (e) => {
e.preventDefault();
};
shortenBtn.onclick = () => {
let xhr = new XMLHttpRequest();
xhr.open("POST", "php/url-controll.php", true);
xhr.onload = () => {
if (xhr.readyState == 4 && xhr.status == 200) {
let data = xhr.response;
if (data.length <= 5) {
// Example of setting the shortened URL directly to the list
let domain = "localhost/url/";
let shortenURL = domain + data;
// Create a new row for the URL and append it to the list
let newRow = `
<div class="data">
<li><a href="${shortenURL}" target="_blank">${shortenURL}</a></li>
<li>${fullURL.value}</li>
<li>0</li>
<li><a href="php/delete.php?id=${data}">Delete</a></li>
</div>
`;
urlsArea.insertAdjacentHTML('afterbegin', newRow);
} else {
alert(data);
}
}
};
let formData = new FormData(form);
xhr.send(formData);
};