-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
79 lines (69 loc) · 2.37 KB
/
index.html
File metadata and controls
79 lines (69 loc) · 2.37 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>teeny.link</title>
</head>
<body>
<h1 style="font-size: 10px">Teeny.link</h1>
<div id="link_div">
Link: <input id="url_field" type="text" /> <button id="shrink_button">shrink it</button> <span id="output_span"></span>
</div>
<div id="loading_div" style="display: none;">
Redirecting to link...
</div>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
var base_url = 'https://eb3km3hgq3.execute-api.us-west-2.amazonaws.com/prod';
function shrink_url() {
var url = $('#url_field').val();
if (!url) {
return;
}
$.ajax(base_url + "?e=" + encodeURIComponent(url))
.success(function (data, textStatus, jqXHR) {
if (data.e) {
var teeny_url = 'http://teeny.link/?d=' + data.e;
$('#output_span').append(
$('<a></a>').attr('href', teeny_url).html(teeny_url));
} else {
console.log("No data returned.");
}
})
.error(function (jqXHR, textStatus, errorThrown) {
alert('Error: ' + jqXHR + ', ' + textStatus + ', ' + errorThrown);
});
}
$('#shrink_button').click(shrink_url);
$("#url_field").keyup(function (e) {
if (e.keyCode == 13) {
shrink_url();
}
});
$(function() {
var h = window.location.href;
var q_index = h.indexOf('?');
if (q_index > -1) {
var pairs = h.substring(q_index + 1).split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
if (pair && pair.length > 1 && pair[0] === 'd') {
$('#link_div').hide();
$('#loading_div').show();
$.ajax(base_url + "?d=" + pair[1])
.success(function (data, textStatus, jqXHR) {
if (data && data.d) {
var loc = (data.d.indexOf('http') !== 0 ? 'http://' : '') + data.d;
window.location = loc;
} else {
console.log("No data returned.");
}
})
.error(function (jqXHR, textStatus, errorThrown) {
alert('Error: ' + jqXHR + ', ' + textStatus + ', ' + errorThrown);
});
}
}
}
});
</script>
</body>
</html>