CHH站内搜索

CHH更好的站内搜索

  1. // ==UserScript==
  2. // @name CHH站内搜索
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.chiphell.com/*
  5. // @grant none
  6. // @version 1.2
  7. // @author liansishen
  8. // @description CHH更好的站内搜索
  9. // @license MPL-2.0
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14. var strMemo,strValue,localSearch;
  15. //获取前一次选择的搜索方式
  16. localSearch = localStorage.getItem('txtSearch');
  17. //站内搜索部分
  18. var form = document.querySelector('#scbar > div:nth-child(2) > form');
  19. //添加下拉框
  20. var objSel = document.createElement("select");
  21. objSel.id = "selSearch";
  22. objSel.options.add(new Option("谷歌","google"));
  23. objSel.options.add(new Option("百度","baidu"));
  24. objSel.options.add(new Option("必应","bing"));
  25. objSel.onchange = function() {
  26. strMemo = " " + objSel.value + "站内搜索";
  27. if (txtSearch.value == '' | txtSearch.value == " bing站内搜索" | txtSearch.value==" google站内搜索" | txtSearch.value== " baidu站内搜索") {txtSearch.value=strMemo}
  28. }
  29. //form.prepend(objSel)
  30. //搜索输入框显示内容修改
  31. var txtSearch = document.getElementsByName('q')[0];
  32. form.insertBefore(objSel,txtSearch);
  33. strMemo = " " + localSearch + "站内搜索";
  34. switch (localSearch) {
  35. case 'google':
  36. objSel.options[0].selected = true;
  37. break;
  38. case 'baidu':
  39. objSel.options[1].selected = true;
  40. break;
  41. case 'bing':
  42. objSel.options[2].selected = true;
  43. break;
  44. default:
  45. objSel.options[0].selected = true;
  46. break;
  47. }
  48. txtSearch.onfocus = function() {
  49. if(txtSearch.value==strMemo) {
  50. txtSearch.value='';
  51. }
  52. }
  53. txtSearch.onblur = function() {
  54. if (txtSearch.value=='') {
  55. txtSearch.value=strMemo;
  56. }
  57. }
  58. txtSearch.value=strMemo;
  59. //替换原搜索按钮的事件
  60. var button = document.getElementsByName('sa')[0]
  61. button.onclick = function (){
  62. strValue = txtSearch.value;
  63. if (strValue == '' | strValue ==" google站内搜索" | strValue == " baidu站内搜索"|txtSearch.value == " bing站内搜索") {return false;}
  64. localStorage.setItem('txtSearch',objSel.value)
  65. switch (objSel.value) {
  66. case 'google':
  67. window.open('https://www.google.com/search?hl=zh-CN&client=opera&q=site:' + encodeURIComponent(location.hostname) +' ' + encodeURIComponent(strValue),'','');
  68. break;
  69. case 'baidu':
  70. window.open('https://www.baidu.com/s?wd= site:' + encodeURIComponent(location.hostname) + ' ' + encodeURIComponent(strValue),'','');
  71. break;
  72. case 'bing':
  73. window.open('https://cn.bing.com/search?q=site:' + encodeURIComponent(location.hostname) + ' ' + encodeURIComponent(strValue),'','');
  74. break;
  75. default:
  76. window.open('https://www.google.com/search?hl=zh-CN&client=opera&q=site:' + encodeURIComponent(location.hostname) +' ' + encodeURIComponent(strValue),'','');
  77. break;
  78. }
  79. return false;
  80. };
  81. })();

QingJ © 2025

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