闲鱼搜索框

为闲鱼添加搜索框

  1. // ==UserScript==
  2. // @name 闲鱼搜索框
  3. // @namespace Scripts
  4. // @version 0.0.1
  5. // @description 为闲鱼添加搜索框
  6. // @author chasen
  7. // @match https://2.taobao.com/*
  8. // @match https://s.2.taobao.com/*
  9. // @grant none
  10. // ==/UserScript==
  11. 'use strict';
  12. !(function() {
  13. var url = "https://2.taobao.com/list/list.htm?q=",
  14. ul = document.getElementById("J_SiteNavBdR"),
  15. li = document.createElement("li"),
  16. div = document.createElement("div"),
  17. inp = document.createElement("input"),
  18. btn = document.createElement("button");
  19. // 输入框
  20. inp.style.width = "70%";
  21. inp.style.border = "1px solid #a2a2a2";
  22. inp.style.background = "none";
  23. if (getParam("q") !== false) inp.value = getParam("q");
  24. inp.onkeydown = function(e) {
  25. if (e.keyCode != "13") return;
  26. window.location.href = url + inp.value.trim();
  27. }
  28. // 搜索按钮
  29. btn.innerText = "搜索";
  30. btn.style.width = "20%";
  31. btn.style.border = "1px solid #a2a2a2";
  32. btn.style.background = "none";
  33. btn.style.marginLeft = "-1px";
  34. btn.onclick = function() {
  35. window.location.href = url + inp.value.trim();
  36. }
  37. // 外层
  38. div.className = "site-nav-menu-hd menu-hd";
  39. li.className = "site-nav-menu menu";
  40. // 添加到页面
  41. div.appendChild(inp);
  42. div.appendChild(btn);
  43. li.appendChild(div);
  44. ul.appendChild(li);
  45.  
  46. function getParam(name) {
  47. var paramArr = window.location.search.substr(1).split('&');
  48. for (var i = 0; i < paramArr.length; i++) {
  49. var keyValue = paramArr[i].split('=');
  50. if (keyValue[0] == name) return decodeURI(keyValue[1]);
  51. }
  52. return false;
  53. }
  54. })();

QingJ © 2025

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