-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
95 lines (84 loc) · 2.34 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled</title>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var username = "USUARIO",
key="APIKEY";
function bit_url(url) {
$.getJSON("http://api.bitly.com/v3/shorten?callback=?",
{
"format": "json",
"apiKey": key,
"login": username,
"longUrl": url,
"domain": 'j.mp'
},
function(response)
{
console.log(response.data.url);
}
);
}
function verifica(url){
$.getJSON("http://api.bitly.com/v3/lookup?callback=?",
{
"format": "json",
"apiKey": key,
"login": username,
"url": url
},
function(response)
{
if(response.data.lookup[0]['error']){
$.getJSON("http://api.bitly.com/v3/shorten?callback=?",{
"format": "json",
"apiKey": key,
"login": username,
"longUrl": url,
"domain": 'j.mp'
}, function(response){
console.log(response.data.url);
}
);
}else{
console.log(response.data.lookup[0]['short_url']);
}
}
);
}
$("#short").click(function(){
var url=$("#url").val();
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var urltest=urlRegex.test(url);
if(urltest){
bit_url(url);
}else{
alert("Bad URL");
}
});
$("#btnVerifica").click(function(){
var url=$("#urlverifica").val();
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var urltest=urlRegex.test(url);
if(urltest){
verifica(url);
}else{
alert("Bad URL");
}
});
});
</script>
//HTML Code
<input type="text" name="url" id="url"/>
<input type="submit" id="short" value="Submit"/>
<input type="text" name="urlverifica" id="urlverifica"/>
<input type="submit" id="btnVerifica" value="Submit"/>
<div id="result"></div>
</body>
</html>