Skip to content

Instantly share code, notes, and snippets.

@elephantsofneptune
Forked from takuya/bitly.js
Created May 14, 2017 13:41
Show Gist options
  • Save elephantsofneptune/cc024c7d4eacae1370a4e62bca31b0f9 to your computer and use it in GitHub Desktop.
Save elephantsofneptune/cc024c7d4eacae1370a4e62bca31b0f9 to your computer and use it in GitHub Desktop.
(function(long_url,callback){
bi = new URL("https://api-ssl.bitly.com/v3/shorten?");
var params = [
"login=YOUR_USER_ID",
"domain=j.mp",
"apiKey=YOUR_API_KEY",
"longUrl="+ encodeURIComponent(long_url)
]
bi.search = "?"+params.join('&')
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var res = JSON.parse(xhr.responseText);
callback(res["data"]["url"])
} else {
alert('There was a problem with the request.');
}
}
}
xhr.open("GET",bi.toString());
xhr.send(null)
})(location.href,function(a){prompt("", a);})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment