aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tinyurl.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/tinyurl.js b/tinyurl.js
new file mode 100644
index 0000000..8c8e132
--- /dev/null
+++ b/tinyurl.js
@@ -0,0 +1,58 @@
+// PLUGIN_INFO//{{{
+var PLUGIN_INFO =
+<VimperatorPlugin>
+ <name>{NAME}</name>
+ <description>tinyurl from vimperator</description>
+ <author mail="konbu.komuro@gmail.com" homepage="http://d.hatena.ne.jp/hogelog/">hogelog</author>
+ <version>0.1</version>
+ <minVersion>2.0pre</minVersion>
+ <maxVersion>2.0pre</maxVersion>
+ <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=';
+ function echopy(str)
+ {
+ liberator.echo(str);
+ util.copyToClipboard(str);
+ }
+
+ commands.add(['tinyurl'], 'echo and copy TinyURL',
+ function(args) echopy(tiny.getTiny(args.length==0 ? buffer.URL : args.string)),
+ {
+ argCount: '?',
+ });
+ commands.add(['expandurl'], 'expand TinyURL',
+ function(args) echopy(tiny.getExpand(args.string)),
+ {
+ argCount: '1',
+ });
+
+ let tiny = plugins.tinyurl = {
+ getTiny: function(url)
+ {
+ return util.httpGet(TinyAPI+encodeURIComponent(url)).responseText;
+ },
+ getExpand: function (url)
+ {
+ return util.httpGet(url).channel.name;
+ }
+ };
+})();
+// vim: fdm=marker sw=4 ts=4 et: