AHOHNMYC

httpS, handy kukarek by hotkey

May 30th, 2017 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         httpS, handy kukarek by hotkey
  3. // @namespace    FM veshtschaniye
  4. // @version      0.0.5.3
  5. // @match        http://anon.fm
  6. // @match        http://alcxemuct.accountant
  7. // @match        https://anon.fm
  8. // @match        https://anon.fm/info.html
  9. // @match        https://anon.fm/menu.html
  10. // @match        https://anon.fm/mobile/a.html
  11. // @match        https://alcxemuct.accountant
  12. // @match        https://alcxemuct.accountant/info.html
  13. // @match        https://alcxemuct.accountant/menu.html
  14. // @match        https://alcxemuct.accountant/mobile/a.html
  15. // @grant        none
  16. // ==/UserScript==
  17.  
  18. // 1. Redirects from HTTP to HTTPS version
  19. // 2. Adds hotkey 'K' to open Kukarekalka window
  20. // 3. Pastes selected text to Kukarekalka window
  21.  
  22. // HTTPS redirection
  23. if (location.protocol[4] !== 's') window.location = location.href.replace('p','ps');
  24.  
  25. // Kukarekalka opener
  26. let kukarekWindow = null;
  27.  
  28. addEventListener('keyup', e => {
  29.     if (e.ctrlKey || e.shiftKey || e.altKey) return;
  30.     const node = document.activeElement.nodeName;
  31.     if (node === 'TEXTAREA' || node === 'INPUT') return;
  32.  
  33.     if (e.code === 'KeyK') {
  34.         if (kukarekWindow && !kukarekWindow.closed) kukarekWindow.focus();
  35.         else kukarekWindow = window.open(`https://${location.host}/feedback/`,'win1feedback','top=-1,left=250,width=560,height=235,toolbar=no');
  36.  
  37.         if (getSelection().toString() !== '') appendText(getSelection().toString().trim().replace(/\n+/g, '\n').replace(/(^|\n)/g, '$1> ')+'\n');
  38.     }
  39. });
  40.  
  41. // Selected text paster
  42. function appendText(text) {
  43.     let t = kukarekWindow.document.getElementById('te');
  44.     if (!t) return setTimeout(()=>appendText(text), 100);
  45.  
  46.     if (t.value.endsWith(text)) return; // Skip if text already pasted
  47.  
  48.     if (t.value !== '' && !t.value.endsWith('\n')) t.value += '\n'; // Add new line to existing text
  49.     t.value += text; // Append selection
  50.     t.selectionStart = -1; // Set cursor to last position
  51. };
Add Comment
Please, Sign In to add comment