-
-
Save davchana/ab936190f7339bb35d93a064db1fe57a to your computer and use it in GitHub Desktop.
goo.gl bookmarklet - this bookmarklet will return the shortened url of the current page
This file contains 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
<a href="javascript:var%20uri=window.location.href;xhr=new%20XMLHttpRequest();xhr.open('POST','https://www.googleapis.com/urlshortener/v1/url',false);xhr.setRequestHeader('Content-Type','application/json');xhr.send(JSON.stringify({longUrl:uri}));var%20json=xhr.responseText;var%20obj=JSON.parse(json);alert(obj.id);">goo.gl this page</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working Code as of Now
Get Key from https://developers.google.com/url-shortener/v1/getting_started#APIKey (&replace XXXXXXXX with it)
Minified above code: (replace XXXX with your key):
Bookmarkified above code: (replace XXXX with your key):
above code will not work without Valid key (Error: Bad Key)