Google Gemini - Direct Links

Removes the google.com/search?q= redirection wrapper from links generated by Google Gemini, allowing you to open external websites directly.

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         Google Gemini - Direct Links
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Removes the google.com/search?q= redirection wrapper from links generated by Google Gemini, allowing you to open external websites directly.
// @author       YourUsername
// @license      MIT
// @match        https://gemini.google.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gemini.google.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to clean the redirect links
    function cleanRedirectLinks() {
        // Select all links starting with the Google Search redirect prefix
        const links = document.querySelectorAll('a[href^="https://www.google.com/search?q="]');

        links.forEach(link => {
            // Prevent processing the same link multiple times
            if (link.dataset.cleaned === "true") return;

            try {
                // Parse the current URL
                const urlObj = new URL(link.href);
                // Extract the 'q' parameter which contains the real URL
                const realUrl = urlObj.searchParams.get('q');

                // Check if realUrl exists and starts with http/https (to avoid breaking legitimate text searches)
                if (realUrl && (realUrl.startsWith('http://') || realUrl.startsWith('https://'))) {

                    // Replace the redirect link with the direct URL
                    link.href = realUrl;

                    // Optional: Force open in new tab to keep Gemini chat active
                    link.target = "_blank";
                    link.rel = "noopener noreferrer";

                    // Mark as cleaned to avoid re-processing
                    link.dataset.cleaned = "true";
                }
            } catch (e) {
                console.error("Gemini Direct Links - Error cleaning link:", e);
            }
        });
    }

    // Create a MutationObserver to handle dynamic content loading (SPA)
    const observer = new MutationObserver((mutations) => {
        cleanRedirectLinks();
    });

    // Start observing the body for changes
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // Initial run
    cleanRedirectLinks();

})();