-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrave-search-default-for-opera.user.js
More file actions
55 lines (44 loc) · 1.41 KB
/
brave-search-default-for-opera.user.js
File metadata and controls
55 lines (44 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ==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');
})();