From 10f8310c7e02aebbfda45bd953a0c972f1c4952d Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Thu, 29 Oct 2009 22:51:03 +0100 Subject: vimperator: include plugins directory --- vimperator/plugin/tinyurl.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 vimperator/plugin/tinyurl.js (limited to 'vimperator/plugin/tinyurl.js') diff --git a/vimperator/plugin/tinyurl.js b/vimperator/plugin/tinyurl.js new file mode 100644 index 0000000..0b86621 --- /dev/null +++ b/vimperator/plugin/tinyurl.js @@ -0,0 +1,35 @@ +/* + * This script adds a tinyurl command to Vimperator + * + * You can map this script adding this to your .vimperatorrc + * :map your_key :exe ":tinyurl "+getBrowser().contentWindow.location.href + * @author: fox (fox91 at anche dot no) + * @version: 0.1 + * +*/ + +commands.addUserCommand(['tinyurl'], + "TinyUrl command", + function(args) { + if (args.length == 1) { + let req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] + .createInstance(Components.interfaces.nsIXMLHttpRequest); + req.open('GET', "http://tinyurl.com/api-create.php?url=" + escape(args[0]), true); + req.onreadystatechange = function (aEvt) { + if (req.readyState == 4) { + if(req.status == 200) { + let clip = Components.classes["@mozilla.org/widget/clipboardhelper;1"]. + getService(Components.interfaces.nsIClipboardHelper); + clip.copyString(req.responseText); + liberator.echo("TinyUrl: " + req.responseText); + } + else + liberator.echoerr("Error contacting tinyurl.com!\n"); + } + }; + req.send(null); + } + else { + liberator.echoerr("Please specify one url"); + } + }); -- cgit v1.2.3