Skip to content

Instantly share code, notes, and snippets.

@alexeyr
Created November 7, 2010 12:51
Show Gist options
  • Save alexeyr/666108 to your computer and use it in GitHub Desktop.
Save alexeyr/666108 to your computer and use it in GitHub Desktop.
// ========================== 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%
// Put your codes here
key.isDisplayableKey = function (ev) {
return ev.charCode !== 0;
};
//}}%PRESERVE%
// ========================================================================= //
// ========================= Special key settings ========================== //
key.quitKey = "undefined";
key.helpKey = "undefined";
key.escapeKey = "Not defined";
key.macroStartKey = "undefined";
key.macroEndKey = "undefined";
key.universalArgumentKey = "undefined";
key.negativeArgument1Key = "undefined";
key.negativeArgument2Key = "undefined";
key.negativeArgument3Key = "undefined";
key.suspendKey = "C-Z";
// ================================= Hooks ================================= //
// ============================= Key bindings ============================== //
key.setViewKey('j', function (ev) {
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
}, 'Scroll line down');
key.setViewKey('k', function (ev) {
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
}, 'Scroll line up');
key.setViewKey('h', function (ev) {
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
}, 'Scroll left');
key.setViewKey('l', function (ev) {
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
}, 'Scroll right');
key.setViewKey([['C-u'], ['C-b']], function (ev) {
goDoCommand("cmd_scrollPageUp");
}, 'Scroll page up');
key.setViewKey('C-d', function (ev) {
goDoCommand("cmd_scrollPageDown");
}, 'Scroll page down');
key.setViewKey(['g', 'g'], function (ev) {
goDoCommand("cmd_scrollTop");
}, 'Scroll to the top of the page', true);
key.setViewKey([['g', 't'], ['C-n']], function (ev) {
getBrowser().mTabContainer.advanceSelectedTab(1, true);
}, 'Select next tab');
key.setViewKey([['g', 'T'], ['C-p']], function (ev) {
getBrowser().mTabContainer.advanceSelectedTab(-1, true);
}, 'Select previous tab');
key.setViewKey(['g', 'u'], function (ev) {
var uri = getBrowser().currentURI;
if (uri.path == "/") {
return;
}
var pathList = uri.path.split("/");
if (!pathList.pop()) {
pathList.pop();
}
loadURI(uri.prePath + pathList.join("/") + ("/"));
}, 'Go upper directory');
key.setViewKey(['g', 'U'], function (ev) {
var uri = window._content.location.href;
if (uri == null) {
return;
}
var root = uri.match(/^[a-z]+:\/\/[^/]+\//);
if (root) {
loadURI(root, null, null);
}
}, 'Go to the root directory');
key.setViewKey('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('H', function (ev) {
BrowserBack();
}, 'Back');
key.setViewKey('L', function (ev) {
BrowserForward();
}, 'Forward');
key.setViewKey('f', function (ev, arg) {
ext.exec("hok-start-foreground-mode", arg);
}, 'Start foreground hint mode', true);
key.setViewKey('F', function (ev, arg) {
ext.exec("hok-start-background-mode", arg);
}, 'Start background hint mode', true);
key.setViewKey(';', function (ev, arg) {
ext.exec("hok-start-extended-mode", arg);
}, 'Start extended hint mode', true);
key.setViewKey('d', function (ev) {
BrowserCloseTabOrWindow();
}, 'Close tab / window');
key.setViewKey('u', function (ev) {
undoCloseTab();
}, 'Undo closed tab');
key.setViewKey('i', function (ev, arg) {
util.setBoolPref("accessibility.browsewithcaret", !util.getBoolPref("accessibility.browsewithcaret"));
}, 'Toggle caret mode', true);
key.setEditKey('C-h', function (ev) {
goDoCommand("cmd_deleteCharBackward");
}, 'Delete backward char');
key.setCaretKey('^', function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectBeginLine") : goDoCommand("cmd_beginLine");
}, 'Move caret to the beginning of the line');
key.setCaretKey([['$'], ['G']], function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectEndLine") : goDoCommand("cmd_endLine");
}, 'Move caret to the end of the line');
key.setCaretKey('j', function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectLineNext") : goDoCommand("cmd_scrollLineDown");
}, 'Move caret to the next line');
key.setCaretKey('k', function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectLinePrevious") : goDoCommand("cmd_scrollLineUp");
}, 'Move caret to the previous line');
key.setCaretKey('l', function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectCharNext") : goDoCommand("cmd_scrollRight");
}, 'Move caret to the right');
key.setCaretKey([['C-h'], ['h']], function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectCharPrevious") : goDoCommand("cmd_scrollLeft");
}, 'Move caret to the left');
key.setCaretKey('w', function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectWordNext") : goDoCommand("cmd_wordNext");
}, 'Move caret to the right by word');
key.setCaretKey('W', function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectWordPrevious") : goDoCommand("cmd_wordPrevious");
}, 'Move caret to the left by word');
key.setCaretKey('SPC', function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectPageNext") : goDoCommand("cmd_movePageDown");
}, 'Move caret down by page');
key.setCaretKey('b', function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectPagePrevious") : goDoCommand("cmd_movePageUp");
}, 'Move caret up by page');
key.setCaretKey(['g', 'g'], function (ev) {
ev.target.ksMarked ? goDoCommand("cmd_selectTop") : goDoCommand("cmd_scrollTop");
}, 'Move caret to the top of the page');
key.setCaretKey([['g', 't'], ['C-n']], function (ev) {
getBrowser().mTabContainer.advanceSelectedTab(1, true);
}, 'Select next tab');
key.setCaretKey([['g', 'T'], ['C-p']], function (ev) {
getBrowser().mTabContainer.advanceSelectedTab(-1, true);
}, 'Select previous tab');
key.setCaretKey(['g', 'u'], function (ev) {
var uri = getBrowser().currentURI;
if (uri.path == "/") {
return;
}
var pathList = uri.path.split("/");
if (!pathList.pop()) {
pathList.pop();
}
loadURI(uri.prePath + pathList.join("/") + ("/"));
}, 'Go upper directory');
key.setCaretKey(['g', 'U'], function (ev) {
var uri = window._content.location.href;
if (uri == null) {
return;
}
var root = uri.match(/^[a-z]+:\/\/[^/]+\//);
if (root) {
loadURI(root, null, null);
}
}, 'Go to the root directory');
key.setCaretKey('C-d', function (ev) {
util.getSelectionController().scrollLine(true);
}, 'Scroll line down');
key.setCaretKey('C-u', 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(':', function (ev, arg) {
shell.input(null, arg);
}, 'List and execute commands', true);
key.setCaretKey('r', function (ev) {
BrowserReload();
}, 'Reload the page', true);
key.setCaretKey('H', function (ev) {
BrowserBack();
}, 'Back');
key.setCaretKey('L', function (ev) {
BrowserForward();
}, 'Forward');
key.setCaretKey('f', function (ev, arg) {
ext.exec("hok-start-foreground-mode", arg);
}, 'Start foreground hint mode', true);
key.setCaretKey('F', function (ev, arg) {
ext.exec("hok-start-background-mode", arg);
}, 'Start background hint mode', true);
key.setCaretKey(';', function (ev, arg) {
ext.exec("hok-start-extended-mode", arg);
}, 'Start extended hint mode', true);
key.setCaretKey('d', function (ev) {
BrowserCloseTabOrWindow();
}, 'Close tab / window');
key.setCaretKey('u', function (ev) {
undoCloseTab();
}, 'Undo closed tab');
key.setCaretKey('i', function (ev, arg) {
util.setBoolPref("accessibility.browsewithcaret", !util.getBoolPref("accessibility.browsewithcaret"));
}, 'Toggle caret mode', true);
let table = {
"q": "й",
"w": "ц",
"e": "у",
"r": "к",
"t": "е",
"y": "н",
"u": "г",
"i": "ш",
"o": "щ",
"p": "з",
"[": "х",
"]": "ъ",
"a": "ф",
"s": "ы",
"d": "в",
"f": "а",
"g": "п",
"h": "р",
"j": "о",
"k": "л",
"l": "д",
";": "ж",
"'": "э",
"z": "я",
"x": "ч",
"c": "с",
"v": "м",
"b": "и",
"n": "т",
"m": "ь",
",": "б",
".": "ю",
"/": "."
};
function replacer(keymap) {
for (let [k, f] in Iterator(keymap)) {
if (typeof keymap[k] === "object")
replacer(keymap[k]);
if (/^(C-|M-)/.test(k))
continue;
if (((k <= 'z' && k >= 'a') || (k <= 'Z' && k >= 'A')) && table[k]) {
keymap[table[k]] = keymap[k];
}
}
}
for (let [mode, keymap] in Iterator(key.keyMapHolder))
{
if (!keymap)
continue;
replacer(keymap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment