Highlight Selected Text

A context menu item which highlights selected text.

当前为 2025-01-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Highlight Selected Text
  3. // @description A context menu item which highlights selected text.
  4. // @author Schimon Jehudah, Adv.
  5. // @namespace i2p.schimon.highlight-selected-text-context-menu
  6. // @homepageURL https://gf.qytechs.cn/en/scripts/467249-switch-page-direction-menu
  7. // @supportURL https://gf.qytechs.cn/en/scripts/467249-switch-page-direction-menu/feedback
  8. // @copyright 2025, Schimon Jehudah (http://schimon.i2p)
  9. // @license Public Domain
  10. // @exclude devtools://*
  11. // @match file:///*
  12. // @match *://*/*
  13. // @version 25.01
  14. // @run-at context-menu
  15. // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn5aN77iPPC90ZXh0Pjwvc3ZnPgo=
  16. // ==/UserScript==
  17.  
  18. (function colorSelectedText() {
  19. const selection = document.getSelection();
  20. if (!selection.rangeCount) return;
  21.  
  22. const range = selection.getRangeAt(0);
  23. const span = document.createElement('span');
  24. span.style.color = 'black';
  25. span.style.background = 'khaki';
  26. range.surroundContents(span);
  27. })();
  28.  
  29.  
  30. // TODO Undo functionality
  31. // Add an event listener to color the selected text on a key press (e.g., pressing 'C')
  32. //document.addEventListener('keypress', function(event) {
  33. // if (event.key === 'c' || event.key === 'C') {
  34. // colorSelectedText();
  35. // }
  36. //});

QingJ © 2025

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