Google Keep Input Tab

Make it possible to input "Tab" in Google Keep

  1. // ==UserScript==
  2. // @name Google Keep Input Tab
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-05-29
  5. // @description Make it possible to input "Tab" in Google Keep
  6. // @author Ravenclaw5874
  7. // @match *://keep.google.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // 원하는 들여쓰기 문자열 (예: 4개의 공백 또는 "\t"로 변경 가능)
  17. const indent = "\t";
  18.  
  19. document.addEventListener('keydown', function(e) {
  20. // Google Keep의 contenteditable div에만 적용
  21. if (e.key === "Tab" && e.target.isContentEditable) {
  22. e.preventDefault(); // 기본 탭 동작을 방지합니다.
  23.  
  24. const selection = window.getSelection();
  25. const range = selection.getRangeAt(0);
  26. let startContainer = range.startContainer;
  27. const startOffset = range.startOffset;
  28. const defaultTextContainer = startContainer.previousElementSibling;
  29.  
  30. // 텍스트 노드가 아닌 경우 텍스트 노드로 변환
  31. if (startContainer.nodeType !== Node.TEXT_NODE) {
  32. if (startContainer.childNodes.length === 0 && defaultTextContainer) {
  33. startContainer.appendChild(document.createTextNode(""));
  34. defaultTextContainer.style.display = 'none';
  35. }
  36. startContainer = startContainer.childNodes[0];
  37. }
  38.  
  39.  
  40. // 들여쓰기 추가
  41. const text = startContainer.textContent;
  42. const beforeText = text.substring(0, startOffset);
  43. const afterText = text.substring(startOffset);
  44. const newText = beforeText + indent + afterText;
  45.  
  46. startContainer.textContent = newText;
  47.  
  48. // 커서를 들여쓰기 뒤에 위치시킴
  49. range.setStart(startContainer, startOffset + indent.length);
  50. range.setEnd(startContainer, startOffset + indent.length);
  51. selection.removeAllRanges();
  52. selection.addRange(range);
  53. }
  54. });
  55. })();

QingJ © 2025

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