-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunshorten.js
35 lines (31 loc) · 1015 Bytes
/
unshorten.js
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
//Create the context menu for right clicking on a link
var context = "link"
var contextItem = chrome.contextMenus.create({"title": "Unshorten","contexts":[context]});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
getLongURL(info.linkUrl);
});
var request = new XMLHttpRequest();
//Finds the "expanded" url from a shortened link
function getLongURL(url){
request.onreadystatechange = processURL();
request.open('GET', url,false);
request.send();
}
//Process the url and catch any exceptions
function processURL(){
try{
if (request.readyState== XMLHttpRequest.DONE){
if (request.status==200){
alert(request.responseURL);
request = new XMLHttpRequest();
//return request.responseURL;
}
else{
alert("An error has occured making the request" + request.status);
}
}
}
catch(e){
alert('Caught Exception: ' + e.description);
}
}