summaryrefslogtreecommitdiff
path: root/vimperator
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
parent06a3f462723471f00ef7d2932b7d47beb1a816c0 (diff)
downloaddotfiles-10f8310c7e02aebbfda45bd953a0c972f1c4952d.tar.xz
vimperator: include plugins directory
Diffstat (limited to 'vimperator')
-rw-r--r--vimperator/plugin/noscript.js142
-rw-r--r--vimperator/plugin/tinyurl.js35
2 files changed, 177 insertions, 0 deletions
diff --git a/vimperator/plugin/noscript.js b/vimperator/plugin/noscript.js
new file mode 100644
index 0000000..3558205
--- /dev/null
+++ b/vimperator/plugin/noscript.js
@@ -0,0 +1,142 @@
+/**
+ * Integration plugin for noscript extension
+ *
+ * Usage:
+ * :noscript info Shows noscript info for the current page.
+ * :noscript popup Opens the noscript popup.
+ * :noscript toggletemp Toggles scripts temporarily on current page.
+ * :noscript toggleperm Toggles scripts permanently on current page.
+ *
+ * Note: when the noscript popup is open, you can scroll through the items
+ * using the following standard vimperator key bindings:
+ * j move down one
+ * k move up one
+ * l open the sub-menu
+ * h close the sub-menu
+ * g jump to the first item in the menu
+ * G jump to the last item in the menu
+ * For implementation simplicity, only single character bindings are supported,
+ * so you cannot supply counts to any of the above.
+ *
+ * Tested against NoScript 1.8.6
+ *
+ * @author Eric Van Dewoestine (ervandew@gmail.com)
+ * @version 0.4
+ *
+ * First two versions written by Martin Stubenschrott, but now maintained by
+ * Eric. Please direct all correspondence regarding this plugin to Eric.
+ */
+
+/**
+ * Class which provides support for noscript commands and hooks into the
+ * noscript popup to provide vimperator scrolling bindings (j,k,l,h,g,G).
+ *
+ * Note: There appears to be a bug in firefox's menupopup key bindings, where
+ * if you navigate to a sub popup (l or right arrow), and navigate back to the
+ * main popup (h or left arrow), then the menupopup seems to lose the ability
+ * to navigate back to the sub menu, and loses the ability to close the main
+ * popup via esc (an alt-tab should still close it). This behavior is
+ * reproducable with or without this plugin.
+ */
+function NoscriptVimperator() {
+ var popup = (
+ noscriptOverlay.stickyUI &&
+ noscriptOverlay.ns.getPref("stickyUI.onKeyboard") &&
+ (popup = noscriptOverlay.stickyUI)
+ ) || document.getElementById("noscript-status-popup");
+ popup.addEventListener('popupshown', popupshown, true);
+ popup.addEventListener('popuphidden', popuphidden, true);
+
+ function popupshown(event){
+ if (event.target == popup){
+ window.addEventListener("keypress", keypress, true);
+ }
+ }
+
+ function popuphidden(event){
+ if (event.target == popup){
+ window.removeEventListener("keypress", keypress, true);
+ }
+ }
+
+ function keypress(event){
+ var keyCode = null;
+ switch(String.fromCharCode(event.which)){
+ case "j":
+ keyCode = 40;
+ break;
+ case "k":
+ keyCode = 38;
+ break;
+ case "l":
+ keyCode = 39;
+ break;
+ case "h":
+ keyCode = 37;
+ break;
+ case "G":
+ keyCode = 35;
+ break;
+ case "g":
+ keyCode = 36;
+ break;
+ default:
+ break;
+ }
+
+ if (keyCode){
+ var newEvent = window.document.createEvent('KeyboardEvent');
+ newEvent.initKeyEvent(
+ "keypress", true, true, null, false, false, false, false, keyCode, 0);
+ popup.dispatchEvent(newEvent);
+ }
+ }
+
+ return {
+ info: function(){
+ liberator.echo(util.objectToString(noscriptOverlay.getSites(), true));
+ },
+
+ popup: function(){
+ noscriptOverlay.showUI();
+ },
+
+ toggletemp: function(){
+ noscriptOverlay.toggleCurrentPage(3);
+ },
+
+ toggleperm: function(){
+ const ns = noscriptOverlay.ns;
+ const url = ns.getQuickSite(content.document.documentURI, /*level*/ 3);
+ noscriptOverlay.safeAllow(url, !ns.isJSEnabled(url), false);
+ },
+
+ _execute: function(args){
+ var name = args.shift();
+ var cmd = nsv[name];
+ if (!cmd){
+ liberator.echoerr('Unsupported noscript command: ' + name);
+ return false;
+ }
+ return cmd(args);
+ },
+
+ _completer: function(context){
+ var commands = [];
+ for (var name in nsv){
+ if (name.indexOf('_') !== 0 && nsv.hasOwnProperty(name)){
+ commands.push(name);
+ }
+ }
+ context.completions = [[c, ''] for each (c in commands)];
+ }
+ };
+}
+
+var nsv = NoscriptVimperator();
+
+commands.addUserCommand(["nosc[ript]"],
+ "Execute noscript commands",
+ function(args) { nsv._execute(args); },
+ { argCount: '1', completer: nsv._completer }
+);
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");
+ }
+ });