-
-
Save phpedinei/dde198cf3c7890778e50fbb7f286e7f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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