Skip to content

Instantly share code, notes, and snippets.

@takuya
Last active February 17, 2019 15:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save takuya/9142242 to your computer and use it in GitHub Desktop.
Save takuya/9142242 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);})
@takuya
Copy link
Author

takuya commented Jan 28, 2015

httpsに変えた

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment