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 🌍🚀🔥

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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