summaryrefslogtreecommitdiff
path: root/vimperator/plugin/tinyurl.js
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-29 22:51:03 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-29 22:51:13 +0100
commit10f8310c7e02aebbfda45bd953a0c972f1c4952d (patch)
tree6f3c0ad2259483d9166c35ec7bc3e4ccfbb80cdf /vimperator/plugin/tinyurl.js
parent06a3f462723471f00ef7d2932b7d47beb1a816c0 (diff)
downloaddotfiles-10f8310c7e02aebbfda45bd953a0c972f1c4952d.tar.xz
vimperator: include plugins directory
Diffstat (limited to 'vimperator/plugin/tinyurl.js')
-rw-r--r--vimperator/plugin/tinyurl.js35
1 files changed, 35 insertions, 0 deletions
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 <silent> your_key :exe ":tinyurl "+getBrowser().contentWindow.location.href<CR>
+ * @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");
+ }
+ });