Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.05 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. //}}%PRESERVE%
  9. // ========================================================================= //
  10.  
  11. // ========================= Special key settings ========================== //
  12.  
  13. key.quitKey = "C-g";
  14. key.helpKey = "<f1>";
  15. key.escapeKey = "C-q";
  16. key.macroStartKey = "<f3>";
  17. key.macroEndKey = "<f4>";
  18. key.suspendKey = "<f2>";
  19. key.universalArgumentKey = "C-u";
  20. key.negativeArgument1Key = "C--";
  21. key.negativeArgument2Key = "C-M--";
  22. key.negativeArgument3Key = "M--";
  23.  
  24. // ================================= Hooks ================================= //
  25.  
  26. hook.addToHook('KeyBoardQuit', function (aEvent) {
  27. if (key.currentKeySequence.length) {
  28. return;
  29. }
  30. command.closeFindBar();
  31. var marked = command.marked(aEvent);
  32. if (util.isCaretEnabled()) {
  33. if (marked) {
  34. command.resetMark(aEvent);
  35. } else {
  36. if ("blur" in aEvent.target) {
  37. aEvent.target.blur();
  38. }
  39. gBrowser.focus();
  40. _content.focus();
  41. }
  42. } else {
  43. goDoCommand("cmd_selectNone");
  44. }
  45. if (KeySnail.windowType === "navigator:browser" && !marked) {
  46. key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
  47. }
  48. });
  49.  
  50. // ============================= Key bindings ============================== //
  51.  
  52. key.setGlobalKey('C-M-r', function (ev) {
  53. userscript.reload();
  54. }, 'Reload the initialization file', true);
  55.  
  56. key.setGlobalKey('M-x', function (ev, arg) {
  57. ext.select(arg, ev);
  58. }, 'List exts and execute selected one', true);
  59.  
  60. key.setGlobalKey('M-:', function (ev) {
  61. command.interpreter();
  62. }, 'Command interpreter', true);
  63.  
  64. key.setGlobalKey(["<f1>", "b"], function (ev) {
  65. key.listKeyBindings();
  66. }, 'List all keybindings', false);
  67.  
  68. key.setGlobalKey('C-m', function (ev) {
  69. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RETURN, true);
  70. }, 'Generate the return key code', false);
  71.  
  72. key.setGlobalKey(["<f1>", "F"], function (ev) {
  73. openHelpLink("firefox-help");
  74. }, 'Display Firefox help', false);
  75.  
  76. key.setGlobalKey(["C-x", "l"], function (ev) {
  77. command.focusToById("urlbar");
  78. }, 'Focus to the location bar', true);
  79.  
  80. key.setGlobalKey(["C-x", "g"], function (ev) {
  81. command.focusToById("searchbar");
  82. }, 'Focus to the search bar', true);
  83.  
  84. key.setGlobalKey(["C-x", "t"], function (ev) {
  85. command.focusElement(command.elementsRetrieverTextarea, 0);
  86. }, 'Focus to the first textarea', true);
  87.  
  88. key.setGlobalKey(["C-x", "s"], function (ev) {
  89. command.focusElement(command.elementsRetrieverButton, 0);
  90. }, 'Focus to the first button', true);
  91.  
  92. key.setGlobalKey('M-w', function (ev) {
  93. command.copyRegion(ev);
  94. }, 'Copy selected text', true);
  95.  
  96. key.setGlobalKey('C-s', function (ev) {
  97. command.iSearchForwardKs(ev);
  98. }, 'Emacs like incremental search forward', true);
  99.  
  100. key.setGlobalKey('C-r', function (ev) {
  101. command.iSearchBackwardKs(ev);
  102. }, 'Emacs like incremental search backward', true);
  103.  
  104. key.setGlobalKey(["C-x", "k"], function (ev) {
  105. BrowserCloseTabOrWindow();
  106. }, 'Close tab / window', false);
  107.  
  108. key.setGlobalKey(["C-x", "K"], function (ev) {
  109. closeWindow(true);
  110. }, 'Close the window', false);
  111.  
  112. key.setGlobalKey(["C-c", "u"], function (ev) {
  113. undoCloseTab();
  114. }, 'Undo closed tab', false);
  115.  
  116. key.setGlobalKey(["C-x", "n"], function (ev) {
  117. OpenBrowserWindow();
  118. }, 'Open new window', false);
  119.  
  120. key.setGlobalKey('C-M-l', function (ev) {
  121. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  122. }, 'Select next tab', false);
  123.  
  124. key.setGlobalKey('C-M-h', function (ev) {
  125. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  126. }, 'Select previous tab', false);
  127.  
  128. key.setGlobalKey(["C-x", "C-c"], function (ev) {
  129. goQuitApplication();
  130. }, 'Exit Firefox', true);
  131.  
  132. key.setGlobalKey(["C-x", "o"], function (ev, arg) {
  133. command.focusOtherFrame(arg);
  134. }, 'Select next frame', false);
  135.  
  136. key.setGlobalKey(["C-x", "1"], function (ev) {
  137. window.loadURI(ev.target.ownerDocument.location.href);
  138. }, 'Show current frame only', true);
  139.  
  140. key.setGlobalKey(["C-x", "C-f"], function (ev) {
  141. BrowserOpenFileWindow();
  142. }, 'Open the local file', true);
  143.  
  144. key.setGlobalKey(["C-x", "C-s"], function (ev) {
  145. saveDocument(window.content.document);
  146. }, 'Save current page to the file', true);
  147.  
  148. key.setGlobalKey(["C-c", "C-c", "C-v"], function (ev) {
  149. toJavaScriptConsole();
  150. }, 'Display JavaScript console', true);
  151.  
  152. key.setGlobalKey(["C-c", "C-c", "C-c"], function (ev) {
  153. command.clearConsole();
  154. }, 'Clear Javascript console', true);
  155.  
  156. key.setEditKey(["C-x", "h"], function (ev) {
  157. command.selectAll(ev);
  158. }, 'Select whole text', true);
  159.  
  160. key.setEditKey([["C-SPC"], ["C-@"]], function (ev) {
  161. command.setMark(ev);
  162. }, 'Set the mark', true);
  163.  
  164. key.setEditKey('C-o', function (ev) {
  165. command.openLine(ev);
  166. }, 'Open line', false);
  167.  
  168. key.setEditKey([["C-x", "u"], ["C-_"]], function (ev) {
  169. display.echoStatusBar("Undo!", 2000);
  170. goDoCommand("cmd_undo");
  171. }, 'Undo', false);
  172.  
  173. key.setEditKey('C-\\', function (ev) {
  174. display.echoStatusBar("Redo!", 2000);
  175. goDoCommand("cmd_redo");
  176. }, 'Redo', false);
  177.  
  178. key.setEditKey('C-a', function (ev) {
  179. command.beginLine(ev);
  180. }, 'Beginning of the line', false);
  181.  
  182. key.setEditKey('C-e', function (ev) {
  183. command.endLine(ev);
  184. }, 'End of the line', false);
  185.  
  186. key.setEditKey('C-f', function (ev) {
  187. command.nextChar(ev);
  188. }, 'Forward char', false);
  189.  
  190. key.setEditKey('C-b', function (ev) {
  191. command.previousChar(ev);
  192. }, 'Backward char', false);
  193.  
  194. key.setEditKey('M-f', function (ev) {
  195. command.forwardWord(ev);
  196. }, 'Next word', false);
  197.  
  198. key.setEditKey('M-b', function (ev) {
  199. command.backwardWord(ev);
  200. }, 'Previous word', false);
  201.  
  202. key.setEditKey('C-n', function (ev) {
  203. command.nextLine(ev);
  204. }, 'Next line', false);
  205.  
  206. key.setEditKey('C-p', function (ev) {
  207. command.previousLine(ev);
  208. }, 'Previous line', false);
  209.  
  210. key.setEditKey('C-v', function (ev) {
  211. command.pageDown(ev);
  212. }, 'Page down', false);
  213.  
  214. key.setEditKey('M-v', function (ev) {
  215. command.pageUp(ev);
  216. }, 'Page up', false);
  217.  
  218. key.setEditKey('M-<', function (ev) {
  219. command.moveTop(ev);
  220. }, 'Beginning of the text area', false);
  221.  
  222. key.setEditKey('M->', function (ev) {
  223. command.moveBottom(ev);
  224. }, 'End of the text area', false);
  225.  
  226. key.setEditKey('C-d', function (ev) {
  227. goDoCommand("cmd_deleteCharForward");
  228. }, 'Delete forward char', false);
  229.  
  230. key.setEditKey('C-h', function (ev) {
  231. goDoCommand("cmd_deleteCharBackward");
  232. }, 'Delete backward char', false);
  233.  
  234. key.setEditKey('M-d', function (ev) {
  235. command.deleteForwardWord(ev);
  236. }, 'Delete forward word', false);
  237.  
  238. key.setEditKey([["C-<backspace>"], ["M-<delete>"]], function (ev) {
  239. command.deleteBackwardWord(ev);
  240. }, 'Delete backward word', false);
  241.  
  242. key.setEditKey('M-u', function (ev, arg) {
  243. command.wordCommand(ev, arg, command.upcaseForwardWord, command.upcaseBackwardWord);
  244. }, 'Convert following word to upper case', false);
  245.  
  246. key.setEditKey('M-l', function (ev, arg) {
  247. command.wordCommand(ev, arg, command.downcaseForwardWord, command.downcaseBackwardWord);
  248. }, 'Convert following word to lower case', false);
  249.  
  250. key.setEditKey('M-c', function (ev, arg) {
  251. command.wordCommand(ev, arg, command.capitalizeForwardWord, command.capitalizeBackwardWord);
  252. }, 'Capitalize the following word', false);
  253.  
  254. key.setEditKey('C-k', function (ev) {
  255. command.killLine(ev);
  256. }, 'Kill the rest of the line', false);
  257.  
  258. key.setEditKey('C-y', command.yank, 'Paste (Yank)', false);
  259.  
  260. key.setEditKey('M-y', command.yankPop, 'Paste pop (Yank pop)', true);
  261.  
  262. key.setEditKey('C-M-y', function (ev) {
  263. if (!command.kill.ring.length) {
  264. return;
  265. }
  266. let (ct = command.getClipboardText()) (!command.kill.ring.length || ct != command.kill.ring[0]) &&
  267. command.pushKillRing(ct);
  268. prompt.selector({message: "Paste:", collection: command.kill.ring, callback: function (i) {if (i >= 0) {key.insertText(command.kill.ring[i]);}}});
  269. }, 'Show kill-ring and select text to paste', true);
  270.  
  271. key.setEditKey('C-w', function (ev) {
  272. goDoCommand("cmd_copy");
  273. goDoCommand("cmd_delete");
  274. command.resetMark(ev);
  275. }, 'Cut current region', true);
  276.  
  277. key.setEditKey(["C-x", "r", "d"], function (ev, arg) {
  278. command.replaceRectangle(ev.originalTarget, "", false, !arg);
  279. }, 'Delete text in the region-rectangle', true);
  280.  
  281. key.setEditKey(["C-x", "r", "t"], function (ev) {
  282. prompt.read("String rectangle: ", function (aStr, aInput) {command.replaceRectangle(aInput, aStr);}, ev.originalTarget);
  283. }, 'Replace text in the region-rectangle with user inputted string', true);
  284.  
  285. key.setEditKey(["C-x", "r", "o"], function (ev) {
  286. command.openRectangle(ev.originalTarget);
  287. }, 'Blank out the region-rectangle, shifting text right', true);
  288.  
  289. key.setEditKey(["C-x", "r", "k"], function (ev, arg) {
  290. command.kill.buffer = command.killRectangle(ev.originalTarget, !arg);
  291. }, 'Delete the region-rectangle and save it as the last killed one', true);
  292.  
  293. key.setEditKey(["C-x", "r", "y"], function (ev) {
  294. command.yankRectangle(ev.originalTarget, command.kill.buffer);
  295. }, 'Yank the last killed rectangle with upper left corner at point', true);
  296.  
  297. key.setEditKey('M-n', function (ev) {
  298. command.walkInputElement(command.elementsRetrieverTextarea, true, true);
  299. }, 'Focus to the next text area', false);
  300.  
  301. key.setEditKey('M-p', function (ev) {
  302. command.walkInputElement(command.elementsRetrieverTextarea, false, true);
  303. }, 'Focus to the previous text area', false);
  304.  
  305. key.setViewKey([["C-n"], ["j"]], function (ev) {
  306. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
  307. }, 'Scroll line down', false);
  308.  
  309. key.setViewKey([["C-p"], ["k"]], function (ev) {
  310. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
  311. }, 'Scroll line up', false);
  312.  
  313. key.setViewKey([["C-f"], ["."]], function (ev) {
  314. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_RIGHT, true);
  315. }, 'Scroll right', false);
  316.  
  317. key.setViewKey([["C-b"], [","]], function (ev) {
  318. key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_LEFT, true);
  319. }, 'Scroll left', false);
  320.  
  321. key.setViewKey([["M-v"], ["b"]], function (ev) {
  322. goDoCommand("cmd_scrollPageUp");
  323. }, 'Scroll page up', false);
  324.  
  325. key.setViewKey('C-v', function (ev) {
  326. goDoCommand("cmd_scrollPageDown");
  327. }, 'Scroll page down', false);
  328.  
  329. key.setViewKey([["M-<"], ["g"]], function (ev) {
  330. goDoCommand("cmd_scrollTop");
  331. }, 'Scroll to the top of the page', true);
  332.  
  333. key.setViewKey([["M->"], ["G"]], function (ev) {
  334. goDoCommand("cmd_scrollBottom");
  335. }, 'Scroll to the bottom of the page', true);
  336.  
  337. key.setViewKey('l', function (ev) {
  338. getBrowser().mTabContainer.advanceSelectedTab(1, true);
  339. }, 'Select next tab', false);
  340.  
  341. key.setViewKey('h', function (ev) {
  342. getBrowser().mTabContainer.advanceSelectedTab(-1, true);
  343. }, 'Select previous tab', false);
  344.  
  345. key.setViewKey(':', function (ev, arg) {
  346. shell.input(null, arg);
  347. }, 'List and execute commands', true);
  348.  
  349. key.setViewKey('R', function (ev) {
  350. BrowserReload();
  351. }, 'Reload the page', true);
  352.  
  353. key.setViewKey('B', function (ev) {
  354. BrowserBack();
  355. }, 'Back', false);
  356.  
  357. key.setViewKey('F', function (ev) {
  358. BrowserForward();
  359. }, 'Forward', false);
  360.  
  361. key.setViewKey(["C-x", "h"], function (ev) {
  362. goDoCommand("cmd_selectAll");
  363. }, 'Select all', true);
  364.  
  365. key.setViewKey('f', function (ev) {
  366. command.focusElement(command.elementsRetrieverTextarea, 0);
  367. }, 'Focus to the first textarea', true);
  368.  
  369. key.setViewKey('M-p', function (ev) {
  370. command.walkInputElement(command.elementsRetrieverButton, true, true);
  371. }, 'Focus to the next button', false);
  372.  
  373. key.setViewKey('M-n', function (ev) {
  374. command.walkInputElement(command.elementsRetrieverButton, false, true);
  375. }, 'Focus to the previous button', false);
  376.  
  377. key.setCaretKey([["C-a"], ["^"]], function (ev) {
  378. ev.target.ksMarked ? goDoCommand("cmd_selectBeginLine") : goDoCommand("cmd_beginLine");
  379. }, 'Move caret to the beginning of the line', false);
  380.  
  381. key.setCaretKey([["C-e"], ["$"]], function (ev) {
  382. ev.target.ksMarked ? goDoCommand("cmd_selectEndLine") : goDoCommand("cmd_endLine");
  383. }, 'Move caret to the end of the line', false);
  384.  
  385. key.setCaretKey([["C-n"], ["j"]], function (ev) {
  386. ev.target.ksMarked ? goDoCommand("cmd_selectLineNext") : goDoCommand("cmd_scrollLineDown");
  387. }, 'Move caret to the next line', false);
  388.  
  389. key.setCaretKey([["C-p"], ["k"]], function (ev) {
  390. ev.target.ksMarked ? goDoCommand("cmd_selectLinePrevious") : goDoCommand("cmd_scrollLineUp");
  391. }, 'Move caret to the previous line', false);
  392.  
  393. key.setCaretKey([["C-f"], ["l"]], function (ev) {
  394. ev.target.ksMarked ? goDoCommand("cmd_selectCharNext") : goDoCommand("cmd_scrollRight");
  395. }, 'Move caret to the right', false);
  396.  
  397. key.setCaretKey([["C-b"], ["h"], ["C-h"]], function (ev) {
  398. ev.target.ksMarked ? goDoCommand("cmd_selectCharPrevious") : goDoCommand("cmd_scrollLeft");
  399. }, 'Move caret to the left', false);
  400.  
  401. key.setCaretKey([["M-f"], ["w"]], function (ev) {
  402. ev.target.ksMarked ? goDoCommand("cmd_selectWordNext") : goDoCommand("cmd_wordNext");
  403. }, 'Move caret to the right by word', false);
  404.  
  405. key.setCaretKey([["M-b"], ["W"]], function (ev) {
  406. ev.target.ksMarked ? goDoCommand("cmd_selectWordPrevious") : goDoCommand("cmd_wordPrevious");
  407. }, 'Move caret to the left by word', false);
  408.  
  409. key.setCaretKey([["C-v"], ["SPC"]], function (ev) {
  410. ev.target.ksMarked ? goDoCommand("cmd_selectPageNext") : goDoCommand("cmd_movePageDown");
  411. }, 'Move caret down by page', false);
  412.  
  413. key.setCaretKey([["M-v"], ["b"]], function (ev) {
  414. ev.target.ksMarked ? goDoCommand("cmd_selectPagePrevious") : goDoCommand("cmd_movePageUp");
  415. }, 'Move caret up by page', false);
  416.  
  417. key.setCaretKey([["M-<"], ["g"]], function (ev) {
  418. ev.target.ksMarked ? goDoCommand("cmd_selectTop") : goDoCommand("cmd_scrollTop");
  419. }, 'Move caret to the top of the page', false);
  420.  
  421. key.setCaretKey([["M->"], ["G"]], function (ev) {
  422. ev.target.ksMarked ? goDoCommand("cmd_selectEndLine") : goDoCommand("cmd_endLine");
  423. }, 'Move caret to the end of the line', false);
  424.  
  425. key.setCaretKey('J', function (ev) {
  426. util.getSelectionController().scrollLine(true);
  427. }, 'Scroll line down', false);
  428.  
  429. key.setCaretKey('K', function (ev) {
  430. util.getSelectionController().scrollLine(false);
  431. }, 'Scroll line up', false);
  432.  
  433. key.setCaretKey(',', function (ev) {
  434. util.getSelectionController().scrollHorizontal(true);
  435. goDoCommand("cmd_scrollLeft");
  436. }, 'Scroll left', false);
  437.  
  438. key.setCaretKey('.', function (ev) {
  439. goDoCommand("cmd_scrollRight");
  440. util.getSelectionController().scrollHorizontal(false);
  441. }, 'Scroll right', false);
  442.  
  443. key.setCaretKey('z', function (ev) {
  444. command.recenter(ev);
  445. }, 'Scroll to the cursor position', false);
  446.  
  447. key.setCaretKey([["C-SPC"], ["C-@"]], function (ev) {
  448. command.setMark(ev);
  449. }, 'Set the mark', true);
  450.  
  451. key.setCaretKey(':', function (ev, arg) {
  452. shell.input(null, arg);
  453. }, 'List and execute commands', true);
  454.  
  455. key.setCaretKey('R', function (ev) {
  456. BrowserReload();
  457. }, 'Reload the page', true);
  458.  
  459. key.setCaretKey('B', function (ev) {
  460. BrowserBack();
  461. }, 'Back', false);
  462.  
  463. key.setCaretKey('F', function (ev) {
  464. BrowserForward();
  465. }, 'Forward', false);
  466.  
  467. key.setCaretKey(["C-x", "h"], function (ev) {
  468. goDoCommand("cmd_selectAll");
  469. }, 'Select all', true);
  470.  
  471. key.setCaretKey('f', function (ev) {
  472. command.focusElement(command.elementsRetrieverTextarea, 0);
  473. }, 'Focus to the first textarea', true);
  474.  
  475. key.setCaretKey('M-p', function (ev) {
  476. command.walkInputElement(command.elementsRetrieverButton, true, true);
  477. }, 'Focus to the next button', false);
  478.  
  479. key.setCaretKey('M-n', function (ev) {
  480. command.walkInputElement(command.elementsRetrieverButton, false, true);
  481. }, 'Focus to the previous button', false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement