Advertisement
Guest User

ph_hotkeys_in_editor.user.js

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