110 lines
3.7 KiB
HTML
110 lines
3.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
<meta name="description" content="The personal URL Shortener">
|
|
<meta name="author" content="">
|
|
|
|
<title>ShortenIt</title>
|
|
|
|
<!-- Bootstrap core CSS -->
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
|
|
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
|
|
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
|
|
|
</head>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var href = window.location.href;
|
|
|
|
$(function() {
|
|
$('#submitButton').click(function() {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/shortenit",
|
|
data: JSON.stringify({'url' : $('#url-input').val(),
|
|
'timestamp': Date.now()}),
|
|
success: returnSuccess,
|
|
dataType: 'json',
|
|
contentType: "application/json",
|
|
});
|
|
});
|
|
});
|
|
|
|
function returnSuccess(data, textStatus, jqXHR) {
|
|
var url = href.concat(data.url);
|
|
console.log(window.location.href)
|
|
if(data.url) {
|
|
document.getElementById("url-result").value = url;
|
|
} else {
|
|
document.getElementById("url-result").value = "Please enter a valid URL!";
|
|
}
|
|
}
|
|
|
|
function copyToClipboard() {
|
|
/* Get the text field */
|
|
var copyText = document.querySelector("#url-result");
|
|
|
|
/* Select the text field */
|
|
copyText.select();
|
|
copyText.setSelectionRange(0, 99999); /*For mobile devices*/
|
|
|
|
/* Copy the text inside the text field */
|
|
document.execCommand("copy");
|
|
|
|
/* Alert the copied text */
|
|
alert("Copied the text: " + copyText.value);
|
|
}
|
|
</script>
|
|
|
|
<body>
|
|
|
|
<!-- Page Content -->
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-lg-12 text-center">
|
|
<h1 class="mt-5">Shorten It!</h1>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="row">
|
|
<div class="col-lg-12 form-group">
|
|
<div class="form-row">
|
|
<div class="col-9">
|
|
<input type="text" class="form-control" name="url" id="url-input" placeholder="https://www.duckduckgo.com" />
|
|
</div>
|
|
<div class="col-3">
|
|
<button id="submitButton" type="button" class="btn btn-outline-primary">Shorten URL</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- <a href="#" id="url-result">Enter URL</a> -->
|
|
|
|
|
|
<div class="row">
|
|
<div class="col-lg-12 form-group">
|
|
<div class="form-row">
|
|
<div class="col-9">
|
|
<input type="text" id="url-result" class="form-control" readonly>
|
|
</div>
|
|
<div class="col-3">
|
|
<button class="btn btn-outline-primary" type="button" id="copy-button" data-toggle="tooltip" onclick="copyToClipboard()" data-placement="button" title="Copy to Clipboard">Copy</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Bootstrap core JavaScript -->
|
|
</body>
|
|
|
|
</html>
|