Custom Search Engine Redirect (Enhanced)

Redirects searches from popular search engines to your preferred engine and adds a sleek, auto-hiding search bar for instant custom searches.

От 18.03.2025. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         Custom Search Engine Redirect (Enhanced)
// @description  Redirects searches from popular search engines to your preferred engine and adds a sleek, auto-hiding search bar for instant custom searches.
// @author       SijosxStudio
// @version      1.0
// @license       MIT
// @match        *://*/*
// @grant        none
// @inject-into  auto
// @run-at       document-start
// @namespace    https://greasyfork.org/users/1375139

// ==/UserScript==
(function () {
    'use strict';

    // CONFIGURATION: Replace with your preferred search engine URL.
    const searchEngineURL = 'https://startpage.com/search?q='; 

    const defaultEngines = [
        'duckduckgo.com',
        'google.com',
        'bing.com',
        'yahoo.com',
        'search.yahoo.com'
    ];

    // REDIRECTION LOGIC
    const currentURL = window.location.href;

    if (defaultEngines.some(engine => currentURL.includes(engine))) {
        const queryParam = new URLSearchParams(window.location.search);
        const query = queryParam.get('q') || queryParam.get('query') || queryParam.get('p');
        if (query) {
            window.location.href = searchEngineURL + encodeURIComponent(query);
        }
    }

    // FLOATING SEARCH BAR (WITH AUTO-HIDE)
    window.addEventListener('DOMContentLoaded', function () {
        const searchBar = document.createElement('div');
        searchBar.id = 'floating-search-bar';
        searchBar.style.position = 'fixed';
        searchBar.style.top = '10px';
        searchBar.style.right = '-220px'; // Start hidden
        searchBar.style.zIndex = '9999';
        searchBar.style.background = 'rgba(0, 0, 0, 0.8)';
        searchBar.style.border = '2px solid #00bfff';
        searchBar.style.borderRadius = '8px';
        searchBar.style.padding = '5px';
        searchBar.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.5)';
        searchBar.style.display = 'flex';
        searchBar.style.alignItems = 'center';
        searchBar.style.transition = 'right 0.3s ease-in-out';

        const inputField = document.createElement('input');
        inputField.type = 'text';
        inputField.placeholder = 'Custom Search...';
        inputField.style.border = 'none';
        inputField.style.outline = 'none';
        inputField.style.padding = '5px';
        inputField.style.flexGrow = '1';
        inputField.style.width = '150px';
        inputField.style.background = 'transparent';
        inputField.style.color = '#fff';

        const searchButton = document.createElement('button');
        searchButton.textContent = 'Go';
        searchButton.style.background = '#00bfff';
        searchButton.style.color = '#fff';
        searchButton.style.border = 'none';
        searchButton.style.padding = '5px 10px';
        searchButton.style.cursor = 'pointer';
        searchButton.style.borderRadius = '4px';

        searchButton.onclick = function () {
            const query = inputField.value.trim();
            if (query) {
                window.location.href = searchEngineURL + encodeURIComponent(query);
            }
        };

        inputField.addEventListener('keypress', function (e) {
            if (e.key === 'Enter') {
                searchButton.click();
            }
        });

        // Auto-hide logic
        const toggleArea = document.createElement('div');
        toggleArea.style.position = 'fixed';
        toggleArea.style.top = '10px';
        toggleArea.style.right = '0';
        toggleArea.style.width = '30px';
        toggleArea.style.height = '30px';
        toggleArea.style.zIndex = '9998';

        toggleArea.addEventListener('mouseenter', () => {
            searchBar.style.right = '10px'; // Show search bar on hover
        });

        searchBar.addEventListener('mouseleave', () => {
            searchBar.style.right = '-220px'; // Auto-hide on mouse leave
        });

        searchBar.appendChild(inputField);
        searchBar.appendChild(searchButton);
        document.body.appendChild(searchBar);
        document.body.appendChild(toggleArea);
    });
})();