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 για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);
    });
})();