-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
162 lines (141 loc) · 4.67 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body, html {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
text-align: center;
margin: 0;
padding: 0;
}
#heading {
padding: .5em;
background-color:lightsteelblue;
border-bottom: 1px solid rgb(154, 167, 184);
font-size: 2em;
font-weight: 600;
color: black;
}
#input {
padding: 3em;
border-top: 1px solid white;
border-bottom: 1px solid rgb(231, 231, 231);
background-color:aliceblue;
color:black;
}
#url {
margin: 1em;
width: 25em;
font-size: 120%;
background-color: white;
border: 1px solid grey;
}
#output {
padding: 1em;
display: none;
background-color:darkorange;
border-top: 1px solid rgb(253, 188, 67);
border-bottom: 1px solid rgb(179, 99, 2);
color:black;
}
#shortcut {
font-size: 1.2em;
font-weight: 600;
}
#error {
padding: 1em;
display: none;
background-color:tomato;
color:black;
}
</style>
</head>
<body onload="UrlChanged(event)">
<div id="heading">
Serverless URL Shortener
</div>
<div id="input">
Enter URL to shorten<br>
<input type="text" id="url" onkeyup="UrlChanged(event)" placeholder="Enter URL to shorten, e.g. http://www.my-long-url.com" autofocus> <br>
<button onclick="ShortcutRequest()" id="shortcutButton" disabled>Get Shortcut</button>
</div>
<div id="output">
<p id="message"></p>
<p id="shortcut"></p>
<button onclick="CopyShortcut()">Copy</button>
<button onclick="OpenShortcut()">Open</button>
</div>
<div id="error"></div>
</body>
</html>
<script>
var xmlHttp = null;
function UrlChanged(event)
{
var button = document.getElementById("shortcutButton");
if(event.which == 13 || event.keyCode == 13)
{
event.preventDefault();
button.click();
}
else
{
if(document.getElementById("url").value.length == 0)
{
button.disabled = true;
}
else
{
button.disabled = false;
}
}
}
function ShortcutRequest()
{
var url = "http://urii.org/api/CreateShortcut?uri="
+ encodeURIComponent(document.getElementById( "url" ).value);
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = ShortcutResponse;
xmlHttp.open( "GET", url, true );
xmlHttp.send( null );
}
function ShortcutResponse()
{
if (xmlHttp.readyState == 4)
{
var response = JSON.parse(xmlHttp.responseText);
if (xmlHttp.status == 200 || xmlHttp.status == 201)
{
document.getElementById("message").innerHTML = response.message;
document.getElementById("shortcut").innerHTML = response.shortcut;
document.getElementById("output").style.display = "block";
document.getElementById("error").style.display = "none";
}
else
{
document.getElementById("error").innerHTML = response.message;
document.getElementById("error").style.display = "block";
document.getElementById("output").style.display = "none";
}
}
}
function CopyShortcut()
{
var copyText = document.getElementById("shortcut").innerHTML;
copyToClipboard(copyText);
}
function OpenShortcut()
{
var shortcut = document.getElementById("shortcut").innerHTML;
window.open(shortcut, '_blank');
}
function copyToClipboard(str)
{
const el = document.createElement('textarea');
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
</script>