// ========================== KeySnail Init File =========================== // // You can preserve your code in this area when generating the init file using GUI. // Put all your code except special key, set*key, hook, blacklist. // ========================================================================= // //{{%PRESERVE% key.setViewKey(["C-x", "b"], function (ev, arg){ ext.exec("tanything", arg); }, "view all tabs", true); key.setViewKey('e', function (aEvent, aArg){ ext.exec("hok-start-foreground-mode", aArg); }, 'Hok - Foreground hint mode', true); key.setViewKey('E', function (aEvent, aArg){ ext.exec("hok-start-background-mode", aArg); }, 'HoK - Background hint mode', true); key.setViewKey(';', function (aEvent, aArg){ ext.exec("hok-start-extended-mode", aArg); }, 'HoK - Extented hint mode', true); key.setViewKey(['C-c', 'C-e'], function (aEvent, aArg){ ext.exec("hok-start-continuous-mode", aArg); }, 'Start continuous HaH', true); key.setViewKey('c', function (aEvent, aArg){ ext.exec("hok-yank-foreground-mode", aArg); }, 'Hok - Foreground yank hint mode', true); plugins.options["bmany.default_open_type"] = "tab"; key.setViewKey(['C-c', 'b'], function (ev, arg) { ext.exec("bmany-list-all-bookmarks", arg, ev); }, 'bmany - List all bookmarks'); key.setViewKey(['C-c', 'h'], function (ev, arg) { ext.exec("history-show", arg, ev); }, 'History - show histories list'); function getShortcutOrURI(k, d) { return PlacesUtils.getURLAndPostDataForKeyword(k)[0]; } key.setViewKey(['C-c', 'r'], function (ev, arg) { if (window.loadURI) { loadURI("javascript:(function(){readStyle%3D'style-apertura'%3BreadSize%3D'size-large'%3BreadMargin%3D'margin-wide'%3B_readability_script%3Ddocument.createElement('SCRIPT')%3B_readability_script.type%3D'text/javascript'%3B_readability_script.src%3D'http://spw.sdf.org/tech/old-readability.js?x%3D'%2B(Math.random())%3Bdocument.getElementsByTagName('head')%5B0%5D.appendChild(_readability_script)%3B_readability_css%3Ddocument.createElement('LINK')%3B_readability_css.rel%3D'stylesheet'%3B_readability_css.href%3D'http://spw.sdf.org/tech/old-readability.css'%3B_readability_css.type%3D'text/css'%3B_readability_css.media%3D'all'%3Bdocument.getElementsByTagName('head')%5B0%5D.appendChild(_readability_css)%3B_readability_print_css%3Ddocument.createElement('LINK')%3B_readability_print_css.rel%3D'stylesheet'%3B_readability_print_css.href%3D'http://spw.sdf.org/tech/old-readability-print.css'%3B_readability_print_css.media%3D'print'%3B_readability_print_css.type%3D'text/css'%3Bdocument.getElementsByTagName('head')%5B0%5D.appendChild(_readability_print_css)%3B})()%3B"); } }, 'Good old Readability'); // http://stackoverflow.com/questions/410411/get-current-page-url-from-a-firefox-sidebar-extension function getCurrentURL(){ var currentWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser"); var currBrowser = currentWindow.getBrowser(); var currURL = currBrowser.currentURI.spec; return currURL; } key.setViewKey(['C-c', 'k'], function (ev, arg){ Components.utils.import("resource://gre/modules/FileUtils.jsm"); // http://stackoverflow.com/questions/10215643/how-to-execute-a-windows-command-from-firefox-addon var env = Components.classes["@mozilla.org/process/environment;1"] .getService(Components.interfaces.nsIEnvironment); var shell = new FileUtils.File("/bin/bash"); var args = ["-c", "reading.py ".concat(getCurrentURL())]; var process = Components.classes["@mozilla.org/process/util;1"] .createInstance(Components.interfaces.nsIProcess); process.init(shell); process.runAsync(args, args.length); }, 'Send to Kindle and add to Org reading list'); key.setViewKey(['C-c', 'v'], function (ev, arg){ Components.utils.import("resource://gre/modules/FileUtils.jsm"); // http://stackoverflow.com/questions/10215643/how-to-execute-a-windows-command-from-firefox-addon var env = Components.classes["@mozilla.org/process/environment;1"] .getService(Components.interfaces.nsIEnvironment); var shell = new FileUtils.File("/bin/bash"); var args = ["-c", "yt ".concat(getCurrentURL())]; var process = Components.classes["@mozilla.org/process/util;1"] .createInstance(Components.interfaces.nsIProcess); process.init(shell); process.runAsync(args, args.length); }, 'Send flash video stream to VLC'); //}}%PRESERVE% // ========================================================================= // // ========================= Special key settings ========================== // key.quitKey = "C-g"; key.helpKey = ""; key.escapeKey = "C-q"; key.macroStartKey = ""; key.macroEndKey = ""; key.universalArgumentKey = "C-u"; key.negativeArgument1Key = "C--"; key.negativeArgument2Key = "C-M--"; key.negativeArgument3Key = "M--"; key.suspendKey = ""; // ================================= Hooks ================================= // hook.setHook('KeyBoardQuit', function (aEvent) { if (key.currentKeySequence.length) return; command.closeFindBar(); let marked = command.marked(aEvent); if (util.isCaretEnabled()) { if (marked) { command.resetMark(aEvent); } else { if ("blur" in aEvent.target) aEvent.target.blur(); gBrowser.focus(); _content.focus(); } } else { goDoCommand("cmd_selectNone"); } if (KeySnail.windowType === "navigator:browser" && !marked) { key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true); } }); // ============================= Key bindings ============================== // key.setGlobalKey(['C-c', 'r'], function (ev) { userscript.reload(); }, 'Reload the initialization file', true); key.setGlobalKey(['C-x', '1'], function (ev) { window.loadURI(ev.target.ownerDocument.location.href); }, 'Show current frame only', true); key.setGlobalKey(['C-x', 'C-m'], function (ev, arg) { ext.select(arg, ev); }, 'List exts and execute selected one', true); key.setGlobalKey(['C-x', 'l'], function (ev) { command.focusToById("urlbar"); }, 'Focus to the location bar', true); key.setGlobalKey(['C-x', 'g'], function (ev) { command.focusToById("searchbar"); }, 'Focus to the search bar', true); key.setGlobalKey(['C-x', 't'], function (ev) { command.focusElement(command.elementsRetrieverTextarea, 0); }, 'Focus to the first textarea', true); key.setGlobalKey(['C-x', 's'], function (ev) { command.focusElement(command.elementsRetrieverButton, 0); }, 'Focus to the first button', true); key.setGlobalKey(['C-x', 'k'], function (ev) { BrowserCloseTabOrWindow(); }, 'Close tab / window'); key.setGlobalKey(['C-x', 'K'], function (ev) { closeWindow(true); }, 'Close the window'); key.setGlobalKey(['C-x', 'n'], function (ev) { OpenBrowserWindow(); }, 'Open new window'); key.setGlobalKey(['C-x', 'C-c'], function (ev) { goQuitApplication(); }, 'Exit Firefox', true); key.setGlobalKey(['C-x', 'o'], function (ev, arg) { command.focusOtherFrame(arg); }, 'Select next frame'); key.setGlobalKey(['C-x', 'C-f'], function (ev) { BrowserOpenFileWindow(); }, 'Open the local file', true); key.setGlobalKey(['C-x', 'C-s'], function (ev) { saveDocument(window.content.document); }, 'Save current page to the file', true); key.setGlobalKey('M-:', function (ev) { command.interpreter(); }, 'Command interpreter', true); key.setGlobalKey(['', 'b'], function (ev) { key.listKeyBindings(); }, 'List all keybindings'); key.setGlobalKey(['', 'F'], function (ev) { openHelpLink("firefox-help"); }, 'Display Firefox help'); key.setGlobalKey('C-m', function (ev) { key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RETURN, true); }, 'Generate the return key code'); key.setGlobalKey('M-w', function (ev) { command.copyRegion(ev); }, 'Copy selected text', true); key.setGlobalKey('C-s', function (ev) { command.iSearchForwardKs(ev); }, 'Emacs like incremental search forward', true); key.setGlobalKey('C-r', function (ev) { command.iSearchBackwardKs(ev); }, 'Emacs like incremental search backward', true); key.setGlobalKey('C-/', function (ev) { undoCloseTab(); }, 'Undo closed tab'); key.setGlobalKey(['C-c', 'C-c', 'C-v'], function (ev) { toJavaScriptConsole(); }, 'Display JavaScript console', true); key.setGlobalKey(['C-c', 'C-c', 'C-c'], function (ev) { command.clearConsole(); }, 'Clear Javascript console', true); key.setViewKey(['C-c', 'j'], function (ev, arg){ ext.exec("tanything", arg); }, 'view all tabs', true) key.setViewKey(['C-x', 'b'], function (ev, arg){ ext.exec("tanything", arg); }, 'view all tabs', true); key.setViewKey(['C-x', 'h'], function (ev) { goDoCommand("cmd_selectAll"); }, 'Select all', true); key.setViewKey('e', function (aEvent, aArg){ ext.exec("hok-start-foreground-mode", aArg); }, 'Hok - Foreground hint mode', true); key.setViewKey('E', function (aEvent, aArg){ ext.exec("hok-start-background-mode", aArg); }, 'HoK - Background hint mode', true); key.setViewKey(';', function (aEvent, aArg){ ext.exec("hok-start-extended-mode", aArg); }, 'HoK - Extented hint mode', true); key.setViewKey(['C-c', 'C-e'], function (aEvent, aArg){ ext.exec("hok-start-continuous-mode", aArg); }, 'Start continuous HaH', true); key.setViewKey(['C-c', 'b'], function (ev, arg) { ext.exec("bmany-list-all-bookmarks", arg, ev); }, 'bmany - List all bookmarks'); key.setViewKey(['C-c', 'h'], function (ev, arg) { ext.exec("history-show", arg, ev); }, 'History - show histories list'); key.setViewKey(['C-c', 'r'], function (ev, arg) { if (window.loadURI) { loadURI("javascript:(function(){readStyle%3D'style-apertura'%3BreadSize%3D'size-large'%3BreadMargin%3D'margin-wide'%3B_readability_script%3Ddocument.createElement('SCRIPT')%3B_readability_script.type%3D'text/javascript'%3B_readability_script.src%3D'http://spw.sdf.org/tech/old-readability.js?x%3D'%2B(Math.random())%3Bdocument.getElementsByTagName('head')%5B0%5D.appendChild(_readability_script)%3B_readability_css%3Ddocument.createElement('LINK')%3B_readability_css.rel%3D'stylesheet'%3B_readability_css.href%3D'http://spw.sdf.org/tech/old-readability.css'%3B_readability_css.type%3D'text/css'%3B_readability_css.media%3D'all'%3Bdocument.getElementsByTagName('head')%5B0%5D.appendChild(_readability_css)%3B_readability_print_css%3Ddocument.createElement('LINK')%3B_readability_print_css.rel%3D'stylesheet'%3B_readability_print_css.href%3D'http://spw.sdf.org/tech/old-readability-print.css'%3B_readability_print_css.media%3D'print'%3B_readability_print_css.type%3D'text/css'%3Bdocument.getElementsByTagName('head')%5B0%5D.appendChild(_readability_print_css)%3B})()%3B"); } }, 'Good old Readability'); key.setViewKey(['C-c', 'k'], function (ev, arg){ Components.utils.import("resource://gre/modules/FileUtils.jsm"); // http://stackoverflow.com/questions/10215643/how-to-execute-a-windows-command-from-firefox-addon var env = Components.classes["@mozilla.org/process/environment;1"] .getService(Components.interfaces.nsIEnvironment); var shell = new FileUtils.File("/bin/bash"); var args = ["-c", "reading.py ".concat(getCurrentURL())]; var process = Components.classes["@mozilla.org/process/util;1"] .createInstance(Components.interfaces.nsIProcess); process.init(shell); process.runAsync(args, args.length); }, 'Send to Kindle and add to Org reading list'); key.setViewKey('c', function (aEvent, aArg){ ext.exec("hok-yank-foreground-mode", aArg); }, 'Hok - Foreground yank hint mode', true); key.setViewKey('C-n', function (ev) { key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true); }, 'Scroll line down'); key.setViewKey('u', function (ev) { undoCloseTab(); }, 'Undo closed tab'); key.setViewKey('C-p', function (ev) { key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true); }, 'Scroll line up'); key.setViewKey([['C-f'], ['.']], function (ev) { key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true); }, 'Scroll right'); key.setViewKey([['C-b'], [',']], function (ev) { key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true); }, 'Scroll left'); key.setViewKey([['M-v'], ['b']], function (ev) { goDoCommand("cmd_scrollPageUp"); }, 'Scroll page up'); key.setViewKey('C-v', function (ev) { goDoCommand("cmd_scrollPageDown"); }, 'Scroll page down'); key.setViewKey([['M-<'], ['g']], function (ev) { goDoCommand("cmd_scrollTop"); }, 'Scroll to the top of the page', true); key.setViewKey([['M->'], ['G']], function (ev) { goDoCommand("cmd_scrollBottom"); }, 'Scroll to the bottom of the page', true); key.setViewKey(':', function (ev, arg) { shell.input(null, arg); }, 'List and execute commands', true); key.setViewKey('R', function (ev) { BrowserReload(); }, 'Reload the page', true); key.setViewKey('B', function (ev) { BrowserBack(); }, 'Back'); key.setViewKey('F', function (ev) { BrowserForward(); }, 'Forward'); key.setViewKey('f', function (ev) { command.focusElement(command.elementsRetrieverTextarea, 0); }, 'Focus to the first textarea', true); key.setViewKey('M-p', function (ev) { command.walkInputElement(command.elementsRetrieverButton, true, true); }, 'Focus to the next button'); key.setViewKey('M-n', function (ev) { command.walkInputElement(command.elementsRetrieverButton, false, true); }, 'Focus to the previous button'); key.setViewKey('q', function (ev) { BrowserCloseTabOrWindow(); }, 'Close tab / window'); key.setViewKey('/', function (ev) { command.iSearchForwardKs(ev); }, 'Emacs like incremental search forward', true); key.setViewKey('?', function (ev) { command.iSearchBackward(); }, 'Incremental search backward', true); key.setEditKey(['C-x', 'h'], function (ev) { command.selectAll(ev); }, 'Select whole text', true); key.setEditKey(['C-x', 'r', 'd'], function (ev, arg) { command.replaceRectangle(ev.originalTarget, "", false, !arg); }, 'Delete text in the region-rectangle', true); key.setEditKey(['C-x', 'r', 't'], function (ev) { prompt.read("String rectangle: ", function (aStr, aInput) { command.replaceRectangle(aInput, aStr); }, ev.originalTarget); }, 'Replace text in the region-rectangle with user inputted string', true); key.setEditKey(['C-x', 'r', 'o'], function (ev) { command.openRectangle(ev.originalTarget); }, 'Blank out the region-rectangle, shifting text right', true); key.setEditKey(['C-x', 'r', 'k'], function (ev, arg) { command.kill.buffer = command.killRectangle(ev.originalTarget, !arg); }, 'Delete the region-rectangle and save it as the last killed one', true); key.setEditKey(['C-x', 'r', 'y'], function (ev) { command.yankRectangle(ev.originalTarget, command.kill.buffer); }, 'Yank the last killed rectangle with upper left corner at point', true); key.setEditKey(['C-x', 'C-k'], function (ev) { goDoCommand("cmd_copy"); goDoCommand("cmd_delete"); command.resetMark(ev); }, 'Cut current region', true); key.setEditKey([['C-/'], ['C-_']], function (ev) { display.echoStatusBar("Undo!", 2000); goDoCommand("cmd_undo"); }, 'Undo'); key.setEditKey([['C-SPC'], ['C-@']], function (ev) { command.setMark(ev); }, 'Set the mark', true); key.setEditKey('C-o', function (ev) { command.openLine(ev); }, 'Open line'); key.setEditKey('C-\\', function (ev) { display.echoStatusBar("Redo!", 2000); goDoCommand("cmd_redo"); }, 'Redo'); key.setEditKey('C-a', function (ev) { command.beginLine(ev); }, 'Beginning of the line'); key.setEditKey('C-e', function (ev) { command.endLine(ev); }, 'End of the line'); key.setEditKey('C-f', function (ev) { command.nextChar(ev); }, 'Forward char'); key.setEditKey('C-b', function (ev) { command.previousChar(ev); }, 'Backward char'); key.setEditKey('M-f', function (ev) { command.forwardWord(ev); }, 'Next word'); key.setEditKey('M-b', function (ev) { command.backwardWord(ev); }, 'Previous word'); key.setEditKey('C-n', function (ev) { command.nextLine(ev); }, 'Next line'); key.setEditKey('C-p', function (ev) { command.previousLine(ev); }, 'Previous line'); key.setEditKey('C-v', function (ev) { command.pageDown(ev); }, 'Page down'); key.setEditKey('M-v', function (ev) { command.pageUp(ev); }, 'Page up'); key.setEditKey('M-<', function (ev) { command.moveTop(ev); }, 'Beginning of the text area'); key.setEditKey('M->', function (ev) { command.moveBottom(ev); }, 'End of the text area'); key.setEditKey('C-d', function (ev) { goDoCommand("cmd_deleteCharForward"); }, 'Delete forward char'); key.setEditKey('C-h', function (ev) { goDoCommand("cmd_deleteCharBackward"); }, 'Delete backward char'); key.setEditKey('M-d', function (ev) { command.deleteForwardWord(ev); }, 'Delete forward word'); key.setEditKey([['C-w'], ['M-']], function (ev) { command.deleteBackwardWord(ev); }, 'Delete backward word'); key.setEditKey('M-u', function (ev, arg) { command.wordCommand(ev, arg, command.upcaseForwardWord, command.upcaseBackwardWord); }, 'Convert following word to upper case'); key.setEditKey('M-l', function (ev, arg) { command.wordCommand(ev, arg, command.downcaseForwardWord, command.downcaseBackwardWord); }, 'Convert following word to lower case'); key.setEditKey('M-c', function (ev, arg) { command.wordCommand(ev, arg, command.capitalizeForwardWord, command.capitalizeBackwardWord); }, 'Capitalize the following word'); key.setEditKey('C-k', function (ev) { command.killLine(ev); }, 'Kill the rest of the line'); key.setEditKey('C-y', command.yank, 'Paste (Yank)'); key.setEditKey('M-y', command.yankPop, 'Paste pop (Yank pop)', true); key.setEditKey('C-M-y', function (ev) { if (!command.kill.ring.length) return; let (ct = command.getClipboardText()) (!command.kill.ring.length || ct != command.kill.ring[0]) && command.pushKillRing(ct); prompt.selector( { message: "Paste:", collection: command.kill.ring, callback: function (i) { if (i >= 0) key.insertText(command.kill.ring[i]); } } ); }, 'Show kill-ring and select text to paste', true); key.setEditKey('M-n', function (ev) { command.walkInputElement(command.elementsRetrieverTextarea, true, true); }, 'Focus to the next text area'); key.setEditKey('M-p', function (ev) { command.walkInputElement(command.elementsRetrieverTextarea, false, true); }, 'Focus to the previous text area'); key.setCaretKey([['C-a'], ['^']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectBeginLine") : goDoCommand("cmd_beginLine"); }, 'Move caret to the beginning of the line'); key.setCaretKey([['C-e'], ['$'], ['M->'], ['G']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectEndLine") : goDoCommand("cmd_endLine"); }, 'Move caret to the end of the line'); key.setCaretKey([['C-n'], ['j']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectLineNext") : goDoCommand("cmd_scrollLineDown"); }, 'Move caret to the next line'); key.setCaretKey([['C-p'], ['k']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectLinePrevious") : goDoCommand("cmd_scrollLineUp"); }, 'Move caret to the previous line'); key.setCaretKey([['C-f'], ['l']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectCharNext") : goDoCommand("cmd_scrollRight"); }, 'Move caret to the right'); key.setCaretKey([['C-b'], ['h'], ['C-h']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectCharPrevious") : goDoCommand("cmd_scrollLeft"); }, 'Move caret to the left'); key.setCaretKey([['M-f'], ['w']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectWordNext") : goDoCommand("cmd_wordNext"); }, 'Move caret to the right by word'); key.setCaretKey([['M-b'], ['W']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectWordPrevious") : goDoCommand("cmd_wordPrevious"); }, 'Move caret to the left by word'); key.setCaretKey([['C-v'], ['SPC']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectPageNext") : goDoCommand("cmd_movePageDown"); }, 'Move caret down by page'); key.setCaretKey([['M-v'], ['b']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectPagePrevious") : goDoCommand("cmd_movePageUp"); }, 'Move caret up by page'); key.setCaretKey([['M-<'], ['g']], function (ev) { ev.target.ksMarked ? goDoCommand("cmd_selectTop") : goDoCommand("cmd_scrollTop"); }, 'Move caret to the top of the page'); key.setCaretKey('J', function (ev) { util.getSelectionController().scrollLine(true); }, 'Scroll line down'); key.setCaretKey('K', function (ev) { util.getSelectionController().scrollLine(false); }, 'Scroll line up'); key.setCaretKey(',', function (ev) { util.getSelectionController().scrollHorizontal(true); goDoCommand("cmd_scrollLeft"); }, 'Scroll left'); key.setCaretKey('.', function (ev) { goDoCommand("cmd_scrollRight"); util.getSelectionController().scrollHorizontal(false); }, 'Scroll right'); key.setCaretKey('z', function (ev) { command.recenter(ev); }, 'Scroll to the cursor position'); key.setCaretKey([['C-SPC'], ['C-@']], function (ev) { command.setMark(ev); }, 'Set the mark', true); key.setCaretKey(':', function (ev, arg) { shell.input(null, arg); }, 'List and execute commands', true); key.setCaretKey('R', function (ev) { BrowserReload(); }, 'Reload the page', true); key.setCaretKey('B', function (ev) { BrowserBack(); }, 'Back'); key.setCaretKey('F', function (ev) { BrowserForward(); }, 'Forward'); key.setCaretKey(['C-x', 'h'], function (ev) { goDoCommand("cmd_selectAll"); }, 'Select all', true); key.setCaretKey('f', function (ev) { command.focusElement(command.elementsRetrieverTextarea, 0); }, 'Focus to the first textarea', true); key.setCaretKey('M-p', function (ev) { command.walkInputElement(command.elementsRetrieverButton, true, true); }, 'Focus to the next button'); key.setCaretKey('M-n', function (ev) { command.walkInputElement(command.elementsRetrieverButton, false, true); }, 'Focus to the previous button'); key.setViewKey('o', function (ev) { getBrowser().mTabContainer.advanceSelectedTab(1, true); }, 'Select next tab'); key.setViewKey('i', function (ev) { getBrowser().mTabContainer.advanceSelectedTab(-1, true); }, 'Select previous tab');