Guest User

Untitled

a guest
Jun 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.28 KB | None | 0 0
  1. // ========================== KeySnail Init File =========================== //
  2.  
  3. // You can preserve your code in this area when generating the init file using GUI.
  4. // Put all your code except special key, set*key, hook, blacklist.
  5. // ========================================================================= //
  6. //{{%PRESERVE%
  7. // Put your codes here
  8.  
  9. key.isDisplayableKey = function (ev) {
  10. return ev.charCode !== 0;
  11. };
  12.  
  13. //}}%PRESERVE%
  14. // ========================================================================= //
  15.  
  16. // ========================= Special key settings ========================== //
  17.  
  18. key.quitKey = "undefined";
  19. key.helpKey = "undefined";
  20. key.escapeKey = "Not defined";
  21. key.macroStartKey = "undefined";
  22. key.macroEndKey = "undefined";
  23. key.universalArgumentKey = "undefined";
  24. key.negativeArgument1Key = "undefined";
  25. key.negativeArgument2Key = "undefined";
  26. key.negativeArgument3Key = "undefined";
  27. key.suspendKey = "C-Z";
  28.  
  29. // ================================= Hooks ================================= //
  30.  
  31. // ============================= Key bindings ============================== //
  32.  
  33. key.setViewKey('j', function (ev) {
  34. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  35. }, 'Scroll line down');
  36.  
  37. key.setViewKey('k', function (ev) {
  38. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  39. }, 'Scroll line up');
  40.  
  41. key.setViewKey('h', function (ev) {
  42. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  43. }, 'Scroll left');
  44.  
  45. key.setViewKey('l', function (ev) {
  46. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  47. }, 'Scroll right');
  48.  
  49. key.setViewKey([['C-u'], ['C-b']], function (ev) {
  50. goDoCommand("cmd_scrollPageUp");
  51. }, 'Scroll page up');
  52.  
  53. key.setViewKey('C-d', function (ev) {
  54. goDoCommand("cmd_scrollPageDown");
  55. }, 'Scroll page down');
  56.  
  57. key.setViewKey(['g', 'g'], function (ev) {
  58. goDoCommand("cmd_scrollTop");
  59. }, 'Scroll to the top of the page', true);
  60.  
  61. key.setViewKey([['g', 't'], ['C-n']], function (ev) {
  62. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  63. }, 'Select next tab');
  64.  
  65. key.setViewKey([['g', 'T'], ['C-p']], function (ev) {
  66. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  67. }, 'Select previous tab');
  68.  
  69. key.setViewKey(['g', 'u'], function (ev) {
  70. var uri = getBrowser().currentURI;
  71. if (uri.path == "/") {
  72. return;
  73. }
  74. var pathList = uri.path.split("/");
  75. if (!pathList.pop()) {
  76. pathList.pop();
  77. }
  78. loadURI(uri.prePath + pathList.join("/") + ("/"));
  79. }, 'Go upper directory');
  80.  
  81. key.setViewKey(['g', 'U'], function (ev) {
  82. var uri = window._content.location.href;
  83. if (uri == null) {
  84. return;
  85. }
  86. var root = uri.match(/^[a-z]+:\/\/[^/]+\//);
  87. if (root) {
  88. loadURI(root, null, null);
  89. }
  90. }, 'Go to the root directory');
  91.  
  92. key.setViewKey('G', function (ev) {
  93. goDoCommand("cmd_scrollBottom");
  94. }, 'Scroll to the bottom of the page', true);
  95.  
  96. key.setViewKey(':', function (ev, arg) {
  97. shell.input(null, arg);
  98. }, 'List and execute commands', true);
  99.  
  100. key.setViewKey('r', function (ev) {
  101. BrowserReload();
  102. }, 'Reload the page', true);
  103.  
  104. key.setViewKey('H', function (ev) {
  105. BrowserBack();
  106. }, 'Back');
  107.  
  108. key.setViewKey('L', function (ev) {
  109. BrowserForward();
  110. }, 'Forward');
  111.  
  112. key.setViewKey('f', function (ev, arg) {
  113. ext.exec("hok-start-foreground-mode", arg);
  114. }, 'Start foreground hint mode', true);
  115.  
  116. key.setViewKey('F', function (ev, arg) {
  117. ext.exec("hok-start-background-mode", arg);
  118. }, 'Start background hint mode', true);
  119.  
  120. key.setViewKey(';', function (ev, arg) {
  121. ext.exec("hok-start-extended-mode", arg);
  122. }, 'Start extended hint mode', true);
  123.  
  124. key.setViewKey('d', function (ev) {
  125. BrowserCloseTabOrWindow();
  126. }, 'Close tab / window');
  127.  
  128. key.setViewKey('u', function (ev) {
  129. undoCloseTab();
  130. }, 'Undo closed tab');
  131.  
  132. key.setViewKey('i', function (ev, arg) {
  133. util.setBoolPref("accessibility.browsewithcaret", !util.getBoolPref("accessibility.browsewithcaret"));
  134. }, 'Toggle caret mode', true);
  135.  
  136. key.setEditKey('C-h', function (ev) {
  137. goDoCommand("cmd_deleteCharBackward");
  138. }, 'Delete backward char');
  139.  
  140. key.setCaretKey('^', function (ev) {
  141. ev.target.ksMarked ? goDoCommand("cmd_selectBeginLine") : goDoCommand("cmd_beginLine");
  142. }, 'Move caret to the beginning of the line');
  143.  
  144. key.setCaretKey([['$'], ['G']], function (ev) {
  145. ev.target.ksMarked ? goDoCommand("cmd_selectEndLine") : goDoCommand("cmd_endLine");
  146. }, 'Move caret to the end of the line');
  147.  
  148. key.setCaretKey('j', function (ev) {
  149. ev.target.ksMarked ? goDoCommand("cmd_selectLineNext") : goDoCommand("cmd_scrollLineDown");
  150. }, 'Move caret to the next line');
  151.  
  152. key.setCaretKey('k', function (ev) {
  153. ev.target.ksMarked ? goDoCommand("cmd_selectLinePrevious") : goDoCommand("cmd_scrollLineUp");
  154. }, 'Move caret to the previous line');
  155.  
  156. key.setCaretKey('l', function (ev) {
  157. ev.target.ksMarked ? goDoCommand("cmd_selectCharNext") : goDoCommand("cmd_scrollRight");
  158. }, 'Move caret to the right');
  159.  
  160. key.setCaretKey([['C-h'], ['h']], function (ev) {
  161. ev.target.ksMarked ? goDoCommand("cmd_selectCharPrevious") : goDoCommand("cmd_scrollLeft");
  162. }, 'Move caret to the left');
  163.  
  164. key.setCaretKey('w', function (ev) {
  165. ev.target.ksMarked ? goDoCommand("cmd_selectWordNext") : goDoCommand("cmd_wordNext");
  166. }, 'Move caret to the right by word');
  167.  
  168. key.setCaretKey('W', function (ev) {
  169. ev.target.ksMarked ? goDoCommand("cmd_selectWordPrevious") : goDoCommand("cmd_wordPrevious");
  170. }, 'Move caret to the left by word');
  171.  
  172. key.setCaretKey('SPC', function (ev) {
  173. ev.target.ksMarked ? goDoCommand("cmd_selectPageNext") : goDoCommand("cmd_movePageDown");
  174. }, 'Move caret down by page');
  175.  
  176. key.setCaretKey('b', function (ev) {
  177. ev.target.ksMarked ? goDoCommand("cmd_selectPagePrevious") : goDoCommand("cmd_movePageUp");
  178. }, 'Move caret up by page');
  179.  
  180. key.setCaretKey(['g', 'g'], function (ev) {
  181. ev.target.ksMarked ? goDoCommand("cmd_selectTop") : goDoCommand("cmd_scrollTop");
  182. }, 'Move caret to the top of the page');
  183.  
  184. key.setCaretKey([['g', 't'], ['C-n']], function (ev) {
  185. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  186. }, 'Select next tab');
  187.  
  188. key.setCaretKey([['g', 'T'], ['C-p']], function (ev) {
  189. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  190. }, 'Select previous tab');
  191.  
  192. key.setCaretKey(['g', 'u'], function (ev) {
  193. var uri = getBrowser().currentURI;
  194. if (uri.path == "/") {
  195. return;
  196. }
  197. var pathList = uri.path.split("/");
  198. if (!pathList.pop()) {
  199. pathList.pop();
  200. }
  201. loadURI(uri.prePath + pathList.join("/") + ("/"));
  202. }, 'Go upper directory');
  203.  
  204. key.setCaretKey(['g', 'U'], function (ev) {
  205. var uri = window._content.location.href;
  206. if (uri == null) {
  207. return;
  208. }
  209. var root = uri.match(/^[a-z]+:\/\/[^/]+\//);
  210. if (root) {
  211. loadURI(root, null, null);
  212. }
  213. }, 'Go to the root directory');
  214.  
  215. key.setCaretKey('C-d', function (ev) {
  216. util.getSelectionController().scrollLine(true);
  217. }, 'Scroll line down');
  218.  
  219. key.setCaretKey('C-u', function (ev) {
  220. util.getSelectionController().scrollLine(false);
  221. }, 'Scroll line up');
  222.  
  223. key.setCaretKey(',', function (ev) {
  224. util.getSelectionController().scrollHorizontal(true);
  225. goDoCommand("cmd_scrollLeft");
  226. }, 'Scroll left');
  227.  
  228. key.setCaretKey('.', function (ev) {
  229. goDoCommand("cmd_scrollRight");
  230. util.getSelectionController().scrollHorizontal(false);
  231. }, 'Scroll right');
  232.  
  233. key.setCaretKey(':', function (ev, arg) {
  234. shell.input(null, arg);
  235. }, 'List and execute commands', true);
  236.  
  237. key.setCaretKey('r', function (ev) {
  238. BrowserReload();
  239. }, 'Reload the page', true);
  240.  
  241. key.setCaretKey('H', function (ev) {
  242. BrowserBack();
  243. }, 'Back');
  244.  
  245. key.setCaretKey('L', function (ev) {
  246. BrowserForward();
  247. }, 'Forward');
  248.  
  249. key.setCaretKey('f', function (ev, arg) {
  250. ext.exec("hok-start-foreground-mode", arg);
  251. }, 'Start foreground hint mode', true);
  252.  
  253. key.setCaretKey('F', function (ev, arg) {
  254. ext.exec("hok-start-background-mode", arg);
  255. }, 'Start background hint mode', true);
  256.  
  257. key.setCaretKey(';', function (ev, arg) {
  258. ext.exec("hok-start-extended-mode", arg);
  259. }, 'Start extended hint mode', true);
  260.  
  261. key.setCaretKey('d', function (ev) {
  262. BrowserCloseTabOrWindow();
  263. }, 'Close tab / window');
  264.  
  265. key.setCaretKey('u', function (ev) {
  266. undoCloseTab();
  267. }, 'Undo closed tab');
  268.  
  269. key.setCaretKey('i', function (ev, arg) {
  270. util.setBoolPref("accessibility.browsewithcaret", !util.getBoolPref("accessibility.browsewithcaret"));
  271. }, 'Toggle caret mode', true);
  272.  
  273. let table = {
  274. "q": "й",
  275. "w": "ц",
  276. "e": "у",
  277. "r": "к",
  278. "t": "е",
  279. "y": "н",
  280. "u": "г",
  281. "i": "ш",
  282. "o": "щ",
  283. "p": "з",
  284. "[": "х",
  285. "]": "ъ",
  286. "a": "ф",
  287. "s": "ы",
  288. "d": "в",
  289. "f": "а",
  290. "g": "п",
  291. "h": "р",
  292. "j": "о",
  293. "k": "л",
  294. "l": "д",
  295. ";": "ж",
  296. "'": "э",
  297. "z": "я",
  298. "x": "ч",
  299. "c": "с",
  300. "v": "м",
  301. "b": "и",
  302. "n": "т",
  303. "m": "ь",
  304. ",": "б",
  305. ".": "ю",
  306. "/": "."
  307. };
  308.  
  309. function replacer(keymap) {
  310. for (let [k, f] in Iterator(keymap)) {
  311. if (typeof keymap[k] === "object")
  312. replacer(keymap[k]);
  313.  
  314. if (/^(C-|M-)/.test(k))
  315. continue;
  316.  
  317. if (((k <= 'z' && k >= 'a') || (k <= 'Z' && k >= 'A')) && table[k]) {
  318. keymap[table[k]] = keymap[k];
  319. }
  320. }
  321. }
  322.  
  323. for (let [mode, keymap] in Iterator(key.keyMapHolder))
  324. {
  325. if (!keymap)
  326. continue;
  327.  
  328. replacer(keymap);
  329. }
Add Comment
Please, Sign In to add comment