搜索框鍵盤功能

try to take over the world!

  1. // ==UserScript==
  2. // @name 搜索框鍵盤功能
  3. // @namespace https://gf.qytechs.cn/zh-CN/scripts/16195-%E6%90%9C%E7%B4%A2%E6%A1%86%E9%8D%B5%E7%9B%A4%E5%8A%9F%E8%83%BD
  4. // @version 0.2
  5. // @description try to take over the world!
  6. // @author zzzmoz
  7. // @include http://www.baidu.com/s*
  8. // @include https://www.baidu.com/s*
  9. // @include https://*.wiktionary.org/wiki/*
  10. // @include https://*.wikipedia.org/wiki/*
  11. // @match https://www.baidu.com/
  12. // @grant none
  13. // ==/UserScript==
  14. /* jshint -W097 */
  15. 'use strict';
  16.  
  17. var domain=window.location.hostname;
  18. var dkw;//搜索框
  19. if(domain.indexOf("baidu.com")>-1){//百度
  20. dkw=document.getElementById("kw");
  21. }
  22. else if(domain.indexOf("wikipedia.org")>-1){//wikitionary
  23. dkw=document.getElementById("searchInput");
  24. }
  25. else if(domain.indexOf("wiktionary.org")>-1){//wikitionary
  26. dkw=document.getElementById("searchInput");
  27. }
  28.  
  29.  
  30. //添加事件
  31. dkw.addEventListener("keydown",function(e){//輸入框通用
  32. var ikeyCode=e.keyCode;
  33. if(ikeyCode==188){
  34. return null;
  35. }
  36. e.stopPropagation();
  37. },true);
  38. document.addEventListener("keydown",function(e){//輸入框通用
  39. var ikeyCode=e.keyCode;
  40. //console.log("a:........"+ikeyCode);
  41. switch(ikeyCode){
  42. case 73: //i
  43. dkw.focus();
  44. dkw.select();
  45. e.preventDefault();
  46. break;
  47. case 188: //,
  48. e.preventDefault();
  49. dkw.blur();
  50. break;
  51. case 229: //,
  52. //e.preventDefault();
  53. //dkw.blur();
  54. break;
  55. default:
  56. }
  57. });
  58. if(domain.indexOf("baidu.com")>-1){//百度
  59. document.addEventListener("keydown",function(e){
  60. var ikeyCode=e.keyCode;
  61. switch(ikeyCode){
  62. case 78: //n
  63. document.querySelector("#page > a:last-child").click();//百度
  64. break;
  65. }
  66. });
  67. }
  68. else if(domain.indexOf("wiktionary.org")>-1 || domain.indexOf("wikipedia.org")>-1){//wikitionary/wikipedia
  69. document.addEventListener("keydown",function(e){
  70. var ikeyCode=e.keyCode;
  71. switch(ikeyCode){
  72. case 72://h,zh
  73. document.querySelector("#p-lang .interwiki-zh > a").click();
  74. break;
  75. case 78://n,ja
  76. document.querySelector("#p-lang .interwiki-ja > a").click();
  77. break;
  78. case 69://e,en
  79. document.querySelector("#p-lang .interwiki-en > a").click();
  80. break;
  81. case 86://v,vi
  82. document.querySelector("#p-lang .interwiki-vi > a").click();
  83. break;
  84. default:
  85. }
  86. });
  87. }
  88.  
  89.  

QingJ © 2025

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