google翻译快捷键聚焦输入框

按 / 键聚焦到输入框

  1. // ==UserScript==
  2. // @name google翻译快捷键聚焦输入框
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.1
  5. // @description 按 / 键聚焦到输入框
  6. // @author meteora
  7. // @match https://translate.google.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=translate.google.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. ;(() => {
  14. //排除iframe
  15. if (window.top !== window.self) {
  16. return
  17. }
  18. //监听事件,按下 / 时触发
  19. document.addEventListener("keyup", function (e) {
  20. if (e.key === "/") {
  21. const textareaDom = document.querySelector("#yDmH0d textarea")
  22. //未聚焦输入框先聚焦
  23. if (document.activeElement !== textareaDom) {
  24. textareaDom.focus()
  25. }
  26. textareaDom.select() // 全选textarea里面的文本
  27. }
  28. })
  29. })()

QingJ © 2025

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