Custom Key Commands

Allows custom key commands in text fields, so far I have added Bold and Italic

当前为 2016-05-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Custom Key Commands
  3. // @namespace PXgamer
  4. // @version 0.5
  5. // @description Allows custom key commands in text fields, so far I have added Bold and Italic
  6. // @author PXgamer
  7. // @include *kat.cr/*
  8. // @require https://gf.qytechs.cn/scripts/19569-jquery-selection-jquery-plugin/code/jQueryselection%20-%20jQuery%20Plugin.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var arrShortCut = [{ name: 'Bold', key: 66, fx: 'bold' }, { name: 'Italic', key: 73, fx: 'italic'}, { name: 'Preview', key: 13, fx: 'preview'}];
  16.  
  17. var ctrl = 17; // CTRL Key
  18. var ctrlKeyActived = false;
  19. var ta = $('textarea#replytext');
  20. var isBBaction = false;
  21. var previewAction = false;
  22.  
  23. $(document).keyup(function(e) {
  24. if (e.which == ctrl) ctrlKeyActived = false;
  25. }).keydown(function(e) {
  26. if (e.which == ctrl) ctrlKeyActived = true;
  27. if (ctrlKeyActived === true && ta.is(":focus")) {
  28. jQuery.each(arrShortCut, function(i) {
  29. if (arrShortCut[i].key == e.which) {
  30. exec(arrShortCut[i].fx, ta);
  31. return;
  32. }
  33. });
  34. }
  35. });
  36.  
  37. function exec(fx, ta) {
  38. console.info(fx);
  39. var strings = [];
  40. switch (fx) {
  41. case 'bold':
  42. strings[0] = "[b]";
  43. strings[2] = "[/b]";
  44. isBBaction = true;
  45. previewAction = false;
  46. break;
  47. case 'italic':
  48. strings[0] = "[i]";
  49. strings[2] = "[/i]";
  50. isBBaction = true;
  51. previewAction = false;
  52. break;
  53. case 'preview':
  54. isBBaction = false;
  55. previewAction = true;
  56. break;
  57. default:
  58. strings[0] = "";
  59. strings[2] = "";
  60. isBBaction = false;
  61. previewAction = false;
  62. }
  63. if (isBBaction === true) {
  64. if (window.getSelection) {
  65. strings[1] = window.getSelection().toString();
  66. } else if (document.selection && document.selection.type != "Control") {
  67. strings[1] = document.selection.createRange().text;
  68. }
  69.  
  70. ta.selection('replace', { text: strings[0]+strings[1]+strings[2] });
  71. }
  72. if (previewAction === true) {
  73. $('span.ka.ka-preview.bbedit-preview[data-preview="#post_preview"]').click();
  74. }
  75. }
  76. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址