Universal Site Search for Arc Browser

Enables site-specific searches with shortcuts for Arc Browser or others. Efficiently handles search queries for various websites.

  1. // ==UserScript==
  2. // @name Universal Site Search for Arc Browser
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Enables site-specific searches with shortcuts for Arc Browser or others. Efficiently handles search queries for various websites.
  6. // @author Your Loyal Assistant
  7. // @match *://*/*
  8. // @grant none
  9. // @run-at document-start
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Public search engine shortcuts
  17. const searchEngines = [
  18. { shortcut: '@youtube', url: 'https://www.youtube.com/results?search_query=%s' },
  19. { shortcut: '@bing', url: 'https://www.bing.com/search?q=%s' },
  20. { shortcut: '@duckduckgo', url: 'https://duckduckgo.com/?q=%s' },
  21. { shortcut: '@yandex', url: 'https://yandex.com/search/?text=%s' },
  22. { shortcut: '@perplexity', url: 'https://www.perplexity.ai/search?q=%s' },
  23. { shortcut: '@pahe', url: 'https://pahe.ink/?s=%s' },
  24. { shortcut: '@mkvdrama', url: 'https://mkvdrama.org/?s=%s' },
  25. { shortcut: '@subsource', url: 'https://subsource.net/search/%s' },
  26. ];
  27.  
  28. // Parse the query string
  29. const params = new URLSearchParams(window.location.search);
  30. const query = params.get('q') || params.get('search_query') || params.get('text');
  31. if (!query) return;
  32.  
  33. // Trim and process query
  34. const trimmedQuery = query.trim();
  35.  
  36. // Match shortcuts with precision
  37. const engine = searchEngines.find(e => trimmedQuery.startsWith(e.shortcut + ' '));
  38. const searchQuery = engine ? trimmedQuery.replace(engine.shortcut, '').trim() : null;
  39.  
  40. if (engine && searchQuery) {
  41. // Stop the current page load
  42. if (window.stop) window.stop();
  43. document.documentElement.innerHTML = '';
  44.  
  45. // Redirect to the target URL
  46. const redirectUrl = engine.url.replace('%s', encodeURIComponent(searchQuery));
  47. location.replace(redirectUrl);
  48.  
  49. // Prevent further script execution
  50. throw new Error('REDIRECT_COMPLETE');
  51. }
  52.  
  53. // If no shortcut matched, do nothing and let the browser handle the query normally
  54. })();