Brave Search Default for Opera

Automatically redirects Yahoo searches to Brave Search

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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');
})();