Enhanced Site Search for Arc Browser (No Shortcut, No Action)

Enables site search for Arc browser; only redirects when shortcuts are used

目前为 2024-12-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Enhanced Site Search for Arc Browser (No Shortcut, No Action)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7
  5. // @description Enables site search for Arc browser; only redirects when shortcuts are used
  6. // @author Your Majesty's 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. // Your original search engine shortcuts
  17. const searchEngines = [
  18. { shortcut: ':y', url: 'https://www.youtube.com/results?search_query=%s' },
  19. { shortcut: ':p', url: 'https://pahe.ink/?s=%s' },
  20. { shortcut: ':m', url: 'https://mkvdrama.org/?s=%s' },
  21. { shortcut: ':ss', url: 'https://subsource.net/search/%s' },
  22. ];
  23.  
  24. // Parse the query string
  25. const params = new URLSearchParams(window.location.search);
  26. const query = params.get('q') || params.get('search_query') || params.get('text');
  27. if (!query) return;
  28.  
  29. // Trim and process query
  30. const trimmedQuery = query.trim();
  31.  
  32. // Match shortcuts with precision
  33. const engine = searchEngines.find(e => trimmedQuery.startsWith(e.shortcut + ' '));
  34. const searchQuery = engine ? trimmedQuery.replace(engine.shortcut, '').trim() : null;
  35.  
  36. if (engine && searchQuery) {
  37. // Stop the current page load
  38. if (window.stop) window.stop();
  39. document.documentElement.innerHTML = '';
  40.  
  41. // Redirect to the target URL
  42. const redirectUrl = engine.url.replace('%s', encodeURIComponent(searchQuery));
  43. location.replace(redirectUrl);
  44.  
  45. // Prevent further script execution
  46. throw new Error('REDIRECT_COMPLETE');
  47. }
  48.  
  49. // If no shortcut matched, do nothing and let the browser handle the query normally
  50. })();