Advertisement
Guest User

ph_hotkeys_in_editor.user.js

a guest
May 22nd, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          prohardver.hu : forum : hotkeys in editor
  3. // @include       http://prohardver.hu/muvelet/*
  4. // @include       http://mobilarena.hu/muvelet/*
  5. // @include       http://logout.hu/muvelet/*
  6. // @include       http://itcafe.hu/muvelet/*
  7. // @include       http://gamepod.hu/muvelet/*
  8. // @include       http://hardverapro.hu/muvelet/*
  9. // @version       1.5
  10. // ==/UserScript==
  11. (function()
  12. {
  13.     var event_handler = function()
  14.     {
  15.         var editor = document.evaluate("//textarea[@name=\"content\"]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  16.         if (editor == null)
  17.             return;
  18.         var buttons = document.evaluate("//input", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  19.         var is_comment = buttons.snapshotItem(0).type == "radio";
  20.         var n = is_comment ? 2 : 0;
  21.         var hotkeys =
  22.         {
  23.             "ctrl-enter"  : buttons.snapshotItem(n++), // send comment
  24.             //"ctrl-s" : ":)",
  25.             //"ctrl-x" : function() { window.alert("pressed"); },
  26.             "ctrl-b" : buttons.snapshotItem(n++), // bold
  27.             "ctrl-i" : buttons.snapshotItem(n++), // italic
  28.             "ctrl-u" : buttons.snapshotItem(n++), // underlined
  29.             "ctrl-s" : buttons.snapshotItem(n++), // strike-through
  30.             "ctrl-o" : buttons.snapshotItem(n++), // off topic
  31.             "ctrl-k" : buttons.snapshotItem(n++), // link
  32.             "ctrl-g" : buttons.snapshotItem(n++), // image
  33.             "ctrl-d" : buttons.snapshotItem(n++), // code
  34.             "ctrl-m" : buttons.snapshotItem(n++), // monospace
  35.             "ctrl-w" : buttons.snapshotItem(n++), // raw
  36.             "ctrl-p" : buttons.snapshotItem(n++), // paragraph
  37.             "ctrl-l" : buttons.snapshotItem(n++), // left-aligned
  38.             "ctrl-r" : buttons.snapshotItem(n++), // right-aligned
  39.             "ctrl-e" : buttons.snapshotItem(n++), // centered
  40.             "ctrl-j" : buttons.snapshotItem(n++)  // justified
  41.         };
  42.        
  43.         if (is_comment)
  44.         {
  45.             hotkeys["ctrl-alt-n"] = buttons.snapshotItem(0); // normal comment
  46.             hotkeys["ctrl-alt-o"] = buttons.snapshotItem(1); // off-topic comment
  47.         }
  48.  
  49.         keylib_initialize(editor, hotkeys);
  50.     }
  51.  
  52.     if (document.body)
  53.         event_handler();
  54.     else
  55.         window.addEventListener("load", event_handler, false);
  56. })();
  57.  
  58. //////////////////////////////////////////
  59. // 1.5 anonymous function
  60. // 1.4 keylib
  61. // 1.3 FF4 kompatibilitás
  62. // 1.2 Chrome kompatibilitás
  63. // 1.1 privát írásakor elcsúszott a billentyűkiosztás
  64. // 1.0 eredeti változat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement