20 lines
510 B
JavaScript
20 lines
510 B
JavaScript
var form = document.getElementById('shorten-form');
|
|
var box = form.elements[0];
|
|
var link = document.getElementById('link');
|
|
var shrt = document.getElementById('shortened');
|
|
|
|
function d(data) {
|
|
link.textContent = data.url;
|
|
link.setAttribute('href', data.url);
|
|
shrt.style.opacity = '1';
|
|
box.value = '';
|
|
}
|
|
|
|
form.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
fetch('/new', { method: 'POST', body: JSON.stringify({ url: box.value })})
|
|
.then(x => x.json())
|
|
.then(d);
|
|
});
|