Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.