-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleshorturl.js
22 lines (22 loc) · 1.08 KB
/
googleshorturl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function loadscript(filename) {
var scr=document.createElement('script');
scr.setAttribute("type","text/javascript");
scr.setAttribute("src",filename);
document.getElementsByTagName("head")[0].appendChild(scr);
}
var waitElm=null;
function urltinyfyprompt_callback(response) {
if(waitElm) waitElm.style.display="none";
var txt="Short URL";
if(response.title && response.title!="") txt+=' for "'+response.title+'"';
else if(response.longurl && response.longurl!="") txt+=" for "+response.longurl;
if(response.tinyurl && response.tinyurl!="")
prompt(txt+":", response.tinyurl);
else
alert("Could not get short URL, try again later." + ((response.error && response.error != "") ? ("nError: " + response.error) : ""));
}
function shortenUrl(elm, long_url, service) {
waitElm=elm.parentNode.nextSibling;
if(waitElm) waitElm.style.display="inline";
loadscript("https://urltinyfy.appspot.com/"+service+"?unify=1&url="+encodeURIComponent(long_url) + "&callback=urltinyfyprompt_callback");
}