搜索引擎切换|搜索跳转(支持PC端+移动端)

快速切换搜索引擎,支持PC端、移动端,自动提取搜索关键词,一键跳转,自动隐藏、自动显示。目前支持谷歌、百度、Yandex、Bilibili、知乎等等

  1. // ==UserScript==
  2. // @name 搜索引擎切换|搜索跳转(支持PC端+移动端)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.3
  5. // @description 快速切换搜索引擎,支持PC端、移动端,自动提取搜索关键词,一键跳转,自动隐藏、自动显示。目前支持谷歌、百度、Yandex、Bilibili、知乎等等
  6. // @author DQIT
  7. // @match *://*.google.com*/search*
  8. // @match *://*.google.com.hk*/search*
  9. // @match *://*.bing.com/search*
  10. // @match *://*.baidu.com/s*
  11. // @match *://chatgpt.com/*
  12. // @match *://metaso.cn/*
  13. // @match *://weixin.sogou.com/weixin*
  14. // @match *://search.bilibili.com/all*
  15. // @match *://m.bilibili.com/search*
  16. // @match *://*.zhihu.com/search*
  17. // @match *://*.xiaohongshu.com/explore*
  18. // @match *://*.douyin.com/search/*
  19. // @match *://*.yandex.com/*
  20. // @match *://*.duckduckgo.com/*
  21. // @match *://*.perplexity.ai/*
  22. // @match *://*.quark.sm.cn/*
  23. // @grant GM_addElement
  24. // @license MIT
  25. // ==/UserScript==
  26.  
  27. (function() {
  28. 'use strict';
  29.  
  30. // 搜索引擎列表
  31. const engins = [
  32. { name: "Google", searchUrl: "https://www.google.com/search?q="},
  33. { name: "Bing", searchUrl: "https://www.bing.com/search?q="},
  34. { name: "百度", searchUrl: "https://www.baidu.com/s?wd="},
  35. { name: "夸克", searchUrl: "https://quark.sm.cn/s?q="},
  36. { name: "Yandex", searchUrl: "https://yandex.com/search/?text="},
  37. { name: "DuckDuckGo", searchUrl: "https://duckduckgo.com/?q="},
  38. { name: "ChatGPT", searchUrl: "https://chatgpt.com/?hints=search&q="},
  39. { name: "秘塔", searchUrl: "https://metaso.cn/?q="},
  40. { name: "Youtube", searchUrl: "https://www.youtube.com/results?search_query="},
  41. { name: "GitHub", searchUrl: "https://github.com/search?q="},
  42. { name: "知乎", searchUrl: "https://www.zhihu.com/search?q="},
  43. { name: "B站", searchUrl: "https://search.bilibili.com/all?keyword="},
  44. { name: "微信", searchUrl: "https://weixin.sogou.com/weixin?type=2&s_from=input&query="},
  45. { name: "小红书", searchUrl: "https://www.xiaohongshu.com/explore?q="},
  46. { name: "抖音", searchUrl: "https://www.douyin.com/search/"},
  47. { name: "Perplexity", searchUrl: "https://www.perplexity.ai/?q="},
  48. ];
  49.  
  50. const paramNames = ["wd", "q", "query", "keyword", "text", "word", "search_query"]
  51.  
  52. function getSearchKeyword() {
  53. const queryString = window.location.search;
  54. if (!queryString) {
  55. return null;
  56. }
  57. const urlParams = new URLSearchParams(queryString);
  58. for (const paramName of paramNames) {
  59. if (urlParams.has(paramName)) {
  60. return urlParams.get(paramName);
  61. }
  62. }
  63. return null;
  64. }
  65.  
  66. function createStyle() {
  67. const style = document.createElement('style');
  68. style.textContent = `
  69. /* 公共样式 */
  70. :root {
  71. --bg-blur: 12px;
  72. --button-spacing: 8px;
  73. }
  74.  
  75. /* 设备检测容器 */
  76. #search-tool-container {
  77. position: fixed;
  78. backdrop-filter: blur(var(--bg-blur));
  79. -webkit-backdrop-filter: blur(var(--bg-blur));
  80. background-color: rgba(255, 255, 255, 0.7);
  81. border-radius: 16px;
  82. box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  83. transition: all 0.3s ease;
  84. z-index: 9999
  85. }
  86.  
  87. /* 彩色模糊背景元素 */
  88. #search-tool-container::before {
  89. content: '';
  90. position: absolute;
  91. inset: 0;
  92. background: radial-gradient(circle at 30% 30%,
  93. rgba(79, 96, 204, 0.2) 0%,
  94. rgba(100, 100, 255, 0.2) 100%);
  95. filter: blur(40px);
  96. z-index: -1;
  97. }
  98.  
  99. /* PC端样式 */
  100. @media (min-width: 768px) {
  101. #search-tool-container {
  102. width: 100px;
  103. height: 700px;
  104. top: 150px;
  105. left: 10px;
  106. padding: 16px 8px;
  107. display: flex;
  108. flex-direction: column;
  109. gap: var(--button-spacing);
  110. }
  111.  
  112. .search-tool-button {
  113. background: rgba(255, 255, 255, 0.15);
  114. border: 1px solid rgba(255, 255, 255, 0.2);
  115. padding: 8px;
  116. border-radius: 8px;
  117. cursor: pointer;
  118. transition: all 0.3s ease;
  119. backdrop-filter: blur(4px);
  120. display: flex;
  121. justify-content: center;
  122. }
  123.  
  124. .search-tool-button:hover {
  125. background: rgba(255, 255, 255, 0.3);
  126. transform: translateX(3px);
  127. }
  128. }
  129.  
  130. /* 移动端样式 */
  131. @media (max-width: 767px) {
  132. #search-tool-container {
  133. width: 100%;
  134. height: 40px;
  135. bottom: 0;
  136. left: 0;
  137. right: 0;
  138. padding: 4px 8px;
  139. display: flex;
  140. overflow-x: auto;
  141. scrollbar-width: none;
  142. border-radius: 8px 8px 0 0;
  143. background: linear-gradient(135deg, rgb(212, 227, 252, 0.4), rgb(240, 239, 253, 0.4));
  144. }
  145.  
  146. #search-tool-container::-webkit-scrollbar {
  147. display: none;
  148. }
  149.  
  150. .search-tool-button {
  151. flex-shrink: 0;
  152. min-width: 60px;
  153. height: 32px;
  154. margin: 0 4px;
  155. padding: 0 12px;
  156. border-radius: 16px;
  157. background: rgba(0, 0, 0, 0.1);
  158. display: flex;
  159. align-items: center;
  160. justify-content: center;
  161. transition: all 0.2s ease;
  162. color: rgba(0, 0, 0, 0.9);
  163. }
  164.  
  165. .search-tool-button:active {
  166. transform: scale(0.95);
  167. }
  168. }
  169.  
  170. /* 白天模式 */
  171. @media (prefers-color-scheme: light) {
  172. #search-tool-container {
  173. background-color: rgba(255, 255, 255, 0.7);
  174. }
  175. }
  176.  
  177. /* 夜间模式 */
  178. @media (prefers-color-scheme: dark) {
  179. #search-tool-container {
  180. background-color: rgba(0, 0, 0, 0.5);
  181. }
  182. }
  183.  
  184. /* 夜间模式按钮调整 */
  185. @media (prefers-color-scheme: dark) {
  186. .search-tool-button {
  187. background: rgba(255, 255, 255, 0.1);
  188. color: rgba(255, 255, 255, 0.9);
  189. }
  190. }
  191. `;
  192. document.head.appendChild(style);
  193. }
  194.  
  195. // 创建按钮
  196. function createSearchTool(){
  197. //创建容器
  198. const container = document.createElement('div');
  199. container.id = 'search-tool-container';
  200.  
  201. //创建按钮
  202. for (const engine of engins) {
  203. const btn = document.createElement('div');
  204. btn.classList.add('search-tool-button')
  205. btn.textContent = engine.name;
  206. // 绑定点击跳转事件
  207. btn.addEventListener('click', function() {
  208. let keyword = getSearchKeyword()
  209. window.open(engine.searchUrl + encodeURIComponent(keyword),'_self')
  210. });
  211. container.appendChild(btn);
  212. }
  213.  
  214. //显示容器
  215. document.body.appendChild(container);
  216.  
  217. let lastScrollTop = 0;
  218. window.addEventListener('scroll', function() {
  219. const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  220.  
  221. if (scrollTop > lastScrollTop) {
  222. // 向下滚动,隐藏横条
  223. container.style.display = 'none';
  224. } else {
  225. // 向上滚动,显示横条
  226. container.style.display = 'inline-flex';
  227. }
  228.  
  229. lastScrollTop = scrollTop;
  230. });
  231.  
  232. }
  233.  
  234. function init(){
  235. let keyword = getSearchKeyword();
  236. if(!keyword){
  237. //未提取到关键词不显示
  238. return;
  239. } else {
  240. createStyle();
  241. createSearchTool(keyword);
  242. }
  243.  
  244. }
  245.  
  246. // 使用 MutationObserver 来确保脚本在动态加载的页面上也能正常工作
  247. const observer = new MutationObserver((mutations, obs) => {
  248. const body = document.querySelector('body');
  249. if (body) {
  250. init();
  251. obs.disconnect();
  252. }
  253. });
  254.  
  255. observer.observe(document.documentElement, {
  256. childList: true,
  257. subtree: true
  258. });
  259.  
  260. })();

QingJ © 2025

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