Smart Redirect to DuckDuckGo

Gerçek aramaları hızlıca DuckDuckGo'ya yönlendirir. Tarayıcı dilini algılar, geçerli değilse İngilizce (en-us) kullanır 🌍🚀🔥

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Smart Redirect to DuckDuckGo
// @namespace    https://github.com/MehmetCanWT
// @version      1.7
// @author       MehmetCanWT
// @match        *://www.google.*/*
// @match        *://www.bing.com/*
// @match        *://yandex.com/*
// @match        *://yandex.com.tr/*
// @grant        none
// @run-at       document-start
// @description Gerçek aramaları hızlıca DuckDuckGo'ya yönlendirir. Tarayıcı dilini algılar, geçerli değilse İngilizce (en-us) kullanır 🌍🚀🔥
// ==/UserScript==

(function() {
    'use strict';

    const url = new URL(window.location.href);

    const isGoogleSearch = url.hostname.includes('google.') && url.pathname === '/search';
    const isBingSearch = url.hostname.includes('bing.com') && url.pathname === '/search';
    const isYandexSearch = url.hostname.includes('yandex.') && url.pathname === '/search/';

    if (isGoogleSearch || isBingSearch || isYandexSearch) {
        const query = url.searchParams.get('q') || url.searchParams.get('text');

        if (query) {
            // Tarayıcı dilini al
            let language = navigator.language ? navigator.language.toLowerCase() : '';

            // Geçerli dil mi kontrol et (örnek: tr-tr, en-us vs.)
            const validLangPattern = /^[a-z]{2}-[a-z]{2}$/;
            if (!validLangPattern.test(language)) {
                language = 'en-us'; // Geçerli değilse İngilizce yap
            }

            const duckduckgoURL = `https://duckduckgo.com/?q=${encodeURIComponent(query)}&kl=${encodeURIComponent(language)}`;

            window.location.replace(duckduckgoURL);
        }
    }
})();