Site Search for Arc Browser

Enables site search for Arc browser and others using shortcuts

  1. // ==UserScript==
  2. // @name Site Search for Arc Browser
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Enables site search for Arc browser and others using shortcuts
  6. // @author Faisal Bhuiyan
  7. // @match *://*/*
  8. // @grant none
  9. // @run-at document-start
  10. // @noframes
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const start = performance.now();
  18. // List of search engines with their shortcuts and URLs
  19. // NOTE: Avoid adding your browser's default search engine to prevent redirect loops
  20. const searchEngines = [
  21. {
  22. shortcut: '@perplexity',
  23. url: 'https://perplexity.ai/search?q=%s'
  24. },
  25. {
  26. shortcut: '@g',
  27. url: 'https://www.google.com/search?q=%s'
  28. },
  29. {
  30. shortcut: '@youtube',
  31. url: 'https://www.youtube.com/results?search_query=%s'
  32. },
  33. {
  34. shortcut: '@morphic',
  35. url: 'https://morphic.sh/search?q=%s'
  36. },
  37. {
  38. shortcut: '@qwant',
  39. url: 'https://www.qwant.com/?q=%s'
  40. },
  41. {
  42. shortcut: '@phind',
  43. url: 'https://www.phind.com/search?q=%s'
  44. },
  45. {
  46. shortcut: '@yandex',
  47. url: 'https://yandex.com/search/?text=%s'
  48. }
  49. ];
  50.  
  51. // Fast hostname check using Set for O(1) lookup
  52. // NOTE: These domains should match the search engines above, excluding your default search engine
  53. const searchDomains = new Set([
  54. 'perplexity.ai',
  55. 'google.com',
  56. 'youtube.com',
  57. 'morphic.sh',
  58. 'qwant.com',
  59. 'phind.com',
  60. 'yandex.com'
  61. ]);
  62. const hostname = location.hostname;
  63. // Exit immediately if we're on a search engine
  64. if ([...searchDomains].some(domain => hostname.includes(domain))) return;
  65.  
  66. // Get query parameters fast
  67. const params = new URLSearchParams(window.location.search);
  68. const query = params.get('q') || params.get('search_query') || params.get('text');
  69. if (!query) return;
  70.  
  71. const trimmedQuery = query.trim();
  72. // Fast lookup using Array.find
  73. const engine = searchEngines.find(e => trimmedQuery.startsWith(e.shortcut));
  74. if (engine) {
  75. const searchQuery = trimmedQuery.replace(engine.shortcut, '').trim();
  76. if (searchQuery) {
  77. // Stop the page load as early as possible
  78. if (window.stop) window.stop();
  79. // Try to prevent any further resource loading
  80. document.documentElement.innerHTML = '';
  81. // Use the fastest redirection method
  82. const redirectUrl = engine.url.replace('%s', encodeURIComponent(searchQuery));
  83. location.replace(redirectUrl);
  84. // Prevent any further script execution
  85. throw new Error('REDIRECT_COMPLETE');
  86. }
  87. }
  88.  
  89. const end = performance.now();
  90. console.debug(`Arc Search executed in ${end - start}ms`);
  91. })();

QingJ © 2025

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