-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathtinyurl.js
50 lines (44 loc) · 1.38 KB
/
tinyurl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// PLUGIN_INFO//{{{
var PLUGIN_INFO = xml`
<VimperatorPlugin>
<name>{NAME}</name>
<description>TinyURL from Vimperator</description>
<author mail="[email protected]" homepage="http://d.hatena.ne.jp/hogelog/">hogelog</author>
<version>0.1</version>
<minVersion>2.0pre</minVersion>
<maxVersion>2.0pre</maxVersion>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/tinyurl.js</updateURL>
<detail><![CDATA[
== COMMANDS ==
tinyurl [URL]:
echo and copy URL
expandurl URL:
expand URL
== LIBRARY ==
plugins.tinyurl.getTiny(url):
return TinyURL
plugins.tinyurl.getExpand(url):
return ExpandURL
]]></detail>
</VimperatorPlugin>`;
//}}}
(function() {
const TinyAPI = 'http://tinyurl.com/api-create.php?url=';
commands.add(['tinyurl'], 'echo and copy TinyURL',
function(args) util.copyToClipboard(tiny.getTiny(args.length==0 ? buffer.URL : args.string), true),
{
argCount: '?',
});
commands.add(['expandurl'], 'expand TinyURL',
function(args) util.copyToClipboard(tiny.getExpand(args.string), true),
{
argCount: '1',
});
var tiny = {
getTiny: function(url)
util.httpGet(TinyAPI+encodeURIComponent(url)).responseText,
getExpand: function (url)
util.httpGet(url).channel.name
};
})();
// vim: fdm=marker sw=4 ts=4 et: