-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
52 lines (43 loc) · 1.28 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<html>
<head>
<title>NiceURL</title>
<style>
</style>
<script>
// sends the AJAX request for the url
function askForNiceURL(uglyURL, callback) {
request = new XMLHttpRequest;
requestURL = "/process?" + encodeURIComponent(uglyURL);
request.open('GET', requestURL, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400){
// Success!
resp = request.responseText
} else {
// We reached our target server, but it returned an error
resp = "ERROR"
}
callback(resp);
}
request.onerror = function() {
// There was a connection error of some sort
}
request.send();
}
function displayNiceURL(niceurl) {
document.getElementById('result').value = niceurl;
document.getElementById('result').focus();
}
function fetch() {
uglyURL = document.getElementById('searchbox').value;
askForNiceURL(uglyURL, displayNiceURL);
}
</script>
</head>
<body>
<h1>NiceURL</h1>
<p>Enter the URL you want to make nicer:</p>
<input type="text" id="searchbox" /><input type="button" value="Go" onclick="fetch()" />
<input type="text" disabled="yeah" id="result" />
</body>
</html>