Brave Search Default for Opera

Automatically redirects Yahoo searches to Brave Search

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Brave Search Default for Opera
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Automatically redirects Yahoo searches to Brave Search
// @match        *://*.yahoo.com/*
// @grant        window.stop
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Configuration
    const config = {
        targetEngine: {
            name: 'Brave Search',
            url: 'https://search.brave.com/search?q=%s'
        }
    };

    // Get query parameter specific to Yahoo
    const params = new URLSearchParams(window.location.search);
    const query = params.get('p');  // Yahoo uses 'p' for search queries

    if (!query) return;

    const trimmedQuery = query.trim();
    if (!trimmedQuery) return;

    // Stop the page load immediately
    window.stop();

    // Clear any existing content and prevent further loading
    if (document.documentElement) {
        document.documentElement.innerHTML = '';
    }

    // Cancel any pending requests
    if (window.stop) {
        window.stop();
    }

    // Redirect to Brave Search using the fastest method
    const redirectUrl = config.targetEngine.url.replace('%s', encodeURIComponent(trimmedQuery));

    try {
        window.location.replace(redirectUrl);
    } catch {
        window.location.href = redirectUrl;
    }

    throw new Error('REDIRECT_COMPLETE');
})();