From f46f04b6807f6cbaeac6c70b0ad2e8fbddd78ffe Mon Sep 17 00:00:00 2001 From: anekos Date: Tue, 25 May 2010 19:26:19 +0000 Subject: expand 対応 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@37706 d0d07461-0603-4401-acd4-de1884942a52 --- bitly.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'bitly.js') diff --git a/bitly.js b/bitly.js index cf7b633..9390e20 100644 --- a/bitly.js +++ b/bitly.js @@ -38,7 +38,7 @@ let PLUGIN_INFO = bit.ly Get short alias by bit.ly and j.mp bit.ly や j.mp で短縮URLを得る - 2.0.3 + 2.1.0 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) @@ -95,7 +95,7 @@ let PLUGIN_INFO = ); } - function shorten (url, domain, callback) { + function shorten (url, domain, command, callback) { function get () { let req = new XMLHttpRequest(); req.onreadystatechange = function () { @@ -104,13 +104,13 @@ let PLUGIN_INFO = if (req.status == 200) return callback && callback(req.responseText, req); else - throw new Error(req.statusText); + return liberator.echoerr(req.statusText); }; let requestUri = - ApiUrl + '/shorten?' + + ApiUrl + '/' + (command || 'shorten') + '?' + 'apiKey=' + auth.password + '&' + 'login=' + auth.username + '&' + - 'uri=' + encodeURIComponent(url) + '&' + + (command !== 'expand' ? 'uri=' : 'shortUrl=') + encodeURIComponent(url) + '&' + 'domain=' + (domain || 'bit.ly') + '&' + 'format=txt'; req.open('GET', requestUri, callback); @@ -142,14 +142,18 @@ let PLUGIN_INFO = 'Copy ' + domain + ' url', function (args) { let url = args.literalArg ? util.stringToURLArray(args.literalArg)[0] : buffer.URL; + let cmd = args['-expand'] ? 'expand' : 'shorten'; - shorten(url, domain, function (short) { + shorten(url, domain, cmd, function (short) { util.copyToClipboard(short); liberator.echo(short + ' <= ' + url); }); }, { literal: 0, + options: [ + [['-expand', '-e'], commands.OPTION_NOARG] + ], completer: function (context) { context.completions = [ [buffer.URL, 'Current URL'] @@ -159,7 +163,7 @@ let PLUGIN_INFO = }, true ); - __context__[name] = function (url, callback) shorten(url, domain, callback); + __context__[name] = function (url, cmd, callback) shorten(url, domain, cmd, callback); }); __context__.get = shorten; -- cgit v1.2.3