Created
January 11, 2011 07:35
-
-
Save teramako/774165 to your computer and use it in GitHub Desktop.
goo.glの短縮URLに変換するvimperatorの設定
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
" 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