Created
November 14, 2011 07:00
-
-
Save teramako/1363416 to your computer and use it in GitHub Desktop.
[Vimperator]Git.io shortener
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
// 以下のコードをテキトウな RCファイル 等に書く | |
// RC ファイルに | |
// :cabbrev -javascript gitio userContenx.gitio() | |
userContext.gitio = function gitioShortener (aURL, aCode, aCallback) { | |
var xhr = new XMLHttpRequest, | |
form = new FormData; | |
xhr.open("POST", "http://git.io", !!aCallback); | |
if (aCallback) { | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState === 4 && xhr.status === 201) { | |
aCallback(xhr.getResponseHeader("Location")); | |
} | |
} | |
} | |
form.append("url", aURL || buffer.URL); | |
if (typeof aCode === "string" && aCode) | |
form.append("code", aCode); | |
xhr.send(form); | |
if (!aCallback && xhr.status === 201) { | |
return xhr.getResponseHeader("Location"); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment