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 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Enhanced Site Search for Arc Browser (No Shortcut, No Action)
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  Enables site search for Arc browser; only redirects when shortcuts are used
// @author       Your Majesty's Loyal Assistant
// @match        *://*/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your original search engine shortcuts
    const searchEngines = [
        { shortcut: ':y', url: 'https://www.youtube.com/results?search_query=%s' },
        { shortcut: ':p', url: 'https://pahe.ink/?s=%s' },
        { shortcut: ':m', url: 'https://mkvdrama.org/?s=%s' },
        { shortcut: ':ss', url: 'https://subsource.net/search/%s' },
    ];

    // Parse the query string
    const params = new URLSearchParams(window.location.search);
    const query = params.get('q') || params.get('search_query') || params.get('text');
    if (!query) return;

    // Trim and process query
    const trimmedQuery = query.trim();

    // Match shortcuts with precision
    const engine = searchEngines.find(e => trimmedQuery.startsWith(e.shortcut + ' '));
    const searchQuery = engine ? trimmedQuery.replace(engine.shortcut, '').trim() : null;

    if (engine && searchQuery) {
        // Stop the current page load
        if (window.stop) window.stop();
        document.documentElement.innerHTML = '';

        // Redirect to the target URL
        const redirectUrl = engine.url.replace('%s', encodeURIComponent(searchQuery));
        location.replace(redirectUrl);

        // Prevent further script execution
        throw new Error('REDIRECT_COMPLETE');
    }

    // If no shortcut matched, do nothing and let the browser handle the query normally
})();