Advertisement
Guest User

Stealth Ping Userscript

a guest
Oct 13th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Stealth ping
  3. // @namespace    http://your.homepage/
  4. // @version      0.1
  5. // @description  enter something useful
  6. // @author       You
  7. // @match        https://chat.stackexchange.com/rooms/240/the-nineteenth-byte
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. function withJQuery(f) {
  12.     var script = document.createElement('script');
  13.     script.type = 'text/javascript';
  14.     script.textContent = '(' + f + ')(jQuery)';
  15.     document.head.appendChild(script);
  16. }
  17. withJQuery(function($){
  18.     function setSelectionRange(input, selectionStart, selectionEnd) {
  19.         if (input.setSelectionRange) {
  20.             input.focus();
  21.             input.setSelectionRange(selectionStart, selectionEnd);
  22.         }
  23.         else if (input.createTextRange) {
  24.             var range = input.createTextRange();
  25.             range.collapse(true);
  26.             range.moveEnd('character', selectionEnd);
  27.             range.moveStart('character', selectionStart);
  28.             range.select();
  29.         }
  30.     }
  31.  
  32.     function setCaretToPos (input, pos) {
  33.         setSelectionRange(input, pos, pos);
  34.     }
  35.     var input = $('#input');
  36.     input.keydown(function(e) {
  37.         if (e.which == 81 && e.ctrlKey) {
  38.             e.preventDefault();
  39.             $(this).val($(this).val() + "[​](http://@)");
  40.             setCaretToPos(this, $(this).val().length - 1);
  41.         }
  42.     });
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement