Insert true new line/line break/blank line in an old interface Reddit post by Shift + Enter

Inserts a true new line/line break/blank line when pressing Shift + Enter in an old interface Reddit textarea. Check out this post to learn more: https://old.reddit.com/r/help/comments/1vjfm9/how_do_i_insert_a_blank_line_between_2_lines_of/

  1. // ==UserScript==
  2. // @name Insert true new line/line break/blank line in an old interface Reddit post by Shift + Enter
  3. // @author NWP
  4. // @description Inserts a true new line/line break/blank line when pressing Shift + Enter in an old interface Reddit textarea. Check out this post to learn more: https://old.reddit.com/r/help/comments/1vjfm9/how_do_i_insert_a_blank_line_between_2_lines_of/
  5. // @namespace https://gf.qytechs.cn/users/877912
  6. // @version 0.1
  7. // @license MIT
  8. // @match *://old.reddit.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function adjustScroll(activeElement) {
  16. let lineHeight = parseFloat(window.getComputedStyle(activeElement).lineHeight);
  17. activeElement.scrollTop += lineHeight * 4;
  18. }
  19.  
  20. document.addEventListener('keydown', function(event) {
  21. let activeElement = document.activeElement;
  22. if (activeElement && activeElement.tagName === 'TEXTAREA') {
  23. if (event.shiftKey && event.key === 'Enter') {
  24. event.preventDefault();
  25. let cursorPos = activeElement.selectionStart;
  26.  
  27. document.execCommand('insertText', false, "\n\n \n\n");
  28.  
  29. activeElement.selectionEnd = cursorPos + 10;
  30.  
  31. adjustScroll(activeElement);
  32. } else if ((event.ctrlKey || event.metaKey) && (event.key === 'z' || event.key === 'Z')) {
  33. setTimeout(() => adjustScroll(activeElement), 0);
  34. } else if ((event.ctrlKey || event.metaKey) && (event.key === 'y' || event.key === 'Y')) {
  35. setTimeout(() => adjustScroll(activeElement), 0);
  36. }
  37. }
  38. });
  39. })();

QingJ © 2025

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