aboutsummaryrefslogtreecommitdiffstats
path: root/bitly.js
diff options
context:
space:
mode:
authoranekos2008-11-07 11:41:54 +0000
committeranekos2008-11-07 11:41:54 +0000
commitfffe7bd127de0f9d7f7a6ec3b2758026aad37848 (patch)
tree08cf677f7cc4612f7d19dc278fc689d38a20b4f9 /bitly.js
parentcc306d3b3e99c8d79508dcda59e18cefef8b014f (diff)
downloadvimperator-plugins-fffe7bd127de0f9d7f7a6ec3b2758026aad37848.tar.bz2
Initial release: bit.ly を使うプラグイン
(tinyurl.com よりちょっと短い) git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@22949 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'bitly.js')
-rw-r--r--bitly.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/bitly.js b/bitly.js
new file mode 100644
index 0000000..28fa211
--- /dev/null
+++ b/bitly.js
@@ -0,0 +1,48 @@
+// ==VimperatorPlugin==
+// @name Bit.ly
+// @description-ja Bit.ly で短縮URLを得る
+// @license Creative Commons 2.1 (Attribution + Share Alike)
+// @version 1.0
+// @minVersion 1.2
+// @maxVersion 2.0pre
+// ==/VimperatorPlugin==
+//
+
+(function () {
+
+ function bitly (uri, callback) {
+ let req = new XMLHttpRequest();
+ req.onreadystatechange = function(){
+ if (req.readyState != 4)
+ return;
+ if (req.status == 200)
+ return callback && callback(req.responseText, req);
+ else
+ throw new Error(req.statusText)
+ };
+ req.open("GET", 'http://bit.ly/api?url=' + uri, callback);
+ req.send(null);
+ return !callback && req.responseText;
+ }
+
+ // commands.removeUserCommand('bitly');
+ commands.addUserCommand(
+ ['bitly'],
+ 'Copy bitly url',
+ function () {
+ bitly(buffer.URL, function (short) {
+ alert(short);
+ util.copyToClipboard(short);
+ liberator.echo('`' + short + "' was copied to clipboard.");
+ });
+ }
+ );
+
+ // 外から使えるように
+ liberator.plugins.bitly = {
+ get: bitly,
+ };
+
+})();
+
+