Skip to content

Instantly share code, notes, and snippets.

@teramako
Created January 11, 2011 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teramako/774165 to your computer and use it in GitHub Desktop.
Save teramako/774165 to your computer and use it in GitHub Desktop.
goo.glの短縮URLに変換するvimperatorの設定
" http://code.google.com/intl/ja/apis/urlshortener/v1/getting_started.html
cabbrev -javascript ggl ggl(buffer.URI)
js <<EOM
userContext.ggl = function getGoogleShortenURL(url, callback) {
let uri = "https://www.googleapis.com/urlshortener/v1/url";
let xhr = new XMLHttpRequest();
xhr.open("POST", uri, !!callback);
if (callback) {
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
callback(JSON.parse(xhr.responseText));
}
}
}
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({ longUrl: url || buffer.URL }));
if (!callback) {
return JSON.parse(xhr.responseText).id;
}
}
EOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment