-
Notifications
You must be signed in to change notification settings - Fork 4
/
old.html
55 lines (54 loc) · 1.55 KB
/
old.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
<html>
<head>
<link />
</head>
<body>
<h1 class="message">Shorten your link!</h1>
<div>
<input name="text" type="url" value id="linkinput" placeholder="Paste a URL to shorten" /> <br />
<br />
<input name="path" type="text" value id="pathinput" placeholder="Custom path (optional)" /> <br />
<br />
<input type="submit" id="myinput" value="Shorten" />
</div>
<p id="message"></p>
<script>
document.getElementById("myinput").onclick = function () {
var link = document.getElementById("linkinput").value;
var data = {
domain: "link.laavesh.xyz",
originalURL: link,
allowDuplicates: false,
};
// add custom path if it exists
if (document.getElementById("pathinput").value != "") {
data.path = document.getElementById("pathinput").value;
}
fetch("https://api.short.io/links/public", {
method: "post",
headers: {
accept: "application/json",
"Content-Type": "application/json",
authorization: "pk_M8NSz2WK3m9gHdH2",
},
body: JSON.stringify(data),
})
.then(function (response) {
return response.json();
})
.then(function (data) {
if (data.error) {
throw data.error;
}
document.getElementById("message").innerHTML = "Your short link is " + data.shortURL;
})
.catch(function (error) {
console.log(error);
document.getElementById("message").innerHTML = error;
});
document.getElementById("linkinput").value = "";
document.getElementById("pathinput").value = "";
};
</script>
</body>
</html>