TesterTV_NewGoogleButtons

The buttons appear in a different order for each google search. My script replaces the standard buttons with the 6 most used ones.

// ==UserScript==
// @name         TesterTV_NewGoogleButtons
// @namespace    http://tampermonkey.net/
// @version      2024-03-21
// @description  The buttons appear in a different order for each google search. My script replaces the standard buttons with the 6 most used ones.
// @author       TesterTV
// @match        https://www.google.com/search*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// ==/UserScript==

(function() {

    // Find all objects with class "..."
    let objects;
    let ContainerTop;
    if (location.href.includes("tbm=isch")) {
        //Images
        objects = document.querySelectorAll('.T47uwc');
        ContainerTop='10';
    } else if (location.search.includes("tbm=vid")) {
        //Videos
        objects = document.querySelectorAll('.XIzzdf:nth-of-type(1)');
        ContainerTop='-10';

        // Select the element to remove
        for (var i = 0; i < 4; i++) {
            var elementToRemove = document.querySelector('.XIzzdf:nth-of-type(2)');
            elementToRemove.remove();
        }
        elementToRemove = document.querySelector('.fKmH1e');
        elementToRemove.remove();

    } else if (location.search.includes("tbm=nws")) {
        //News
        objects = document.querySelectorAll('.XIzzdf:nth-of-type(1)');
        ContainerTop='-10';

        // Select the element to remove
        for (var j = 0; j < 4; j++) {
            var elementToRemove2 = document.querySelector('.XIzzdf:nth-of-type(2)');
            elementToRemove2.remove();
        }
        elementToRemove2 = document.querySelector('.fKmH1e');
        elementToRemove2.remove();

    } else if (location.search.includes("?q=") || location.search.includes("sca_esv")) {
        //Ordinary search or
        objects = document.querySelectorAll('.crJ18e');

        if (objects.length === 0) {
            objects = document.querySelectorAll('.IUOThf');
        }

        ContainerTop='-10';
    }

    // Loop through each object and replace with container
    objects.forEach(object => {
        const container = document.createElement('div');
        container.classList.add('container');
        container.style.height = '60px';
        container.style.marginTop = ContainerTop + 'px'; // corrected the style property
        container.style.display = 'flex';
        container.style.alignItems = 'center';

        // Create 5 buttons
        function createButton(text) {
            const button = document.createElement('button');
            button.textContent = text;
            button.style.height = '35px';
            button.style.borderRadius = '15px';
            button.style.backgroundColor = '#202124';
            button.style.color = '#f1f3f4';
            button.style.borderColor = '#3c4043';
            button.style.marginRight = '5px';
            button.style.padding = '0 15px';

            button.addEventListener('mouseover', function() {
                button.style.backgroundColor = '#1eaaf0';
            });
            button.addEventListener('mouseout', function() {
                button.style.backgroundColor = '#202124';
            });
            button.addEventListener('click', function() {

                // Get the text from the search field
                var searchText = document.querySelector('input[name="q"]').value;

                if (text === 'Web') {
                    location.href="https://www.google.com/search?q=" + searchText;
                } else if (text === 'Images') {
                    location.href="https://www.google.com/search?tbm=isch&q=" + searchText;
                } else if (text === 'Videos') {
                    location.href="https://www.google.com/search?tbm=vid&q=" + searchText;
                } else if (text === 'Map') {
                    location.href="https://www.google.com/maps/search/" + searchText;
                } else if (text === 'Translate') {
                    location.href="https://translate.google.com/?sl=auto&tl=en&text=" + searchText;
                } else if (text === 'News') {
                    location.href="https://www.google.com/search?tbm=nws&q=" + searchText;
                }


                button.style.backgroundColor = '#1782b7';
                setTimeout(function() {
                    button.style.backgroundColor = '#1eaaf0';
                }, 100);
            });

            button.addEventListener('mousedown', handleMiddleButtonClick);
            // Event handler for middle mouse button click
            function handleMiddleButtonClick(event) {
                // Check if the middle mouse button was clicked
                if (event.button === 1) {
                // Get the text from the search field
                var searchText = document.querySelector('input[name="q"]').value;

                if (text === 'Web') {
                    window.open("https://www.google.com/search?q=" + searchText, '_blank');
                } else if (text === 'Images') {
                    window.open("https://www.google.com/search?tbm=isch&q=" + searchText, '_blank');
                } else if (text === 'Videos') {
                    window.open("https://www.google.com/search?tbm=vid&q=" + searchText, '_blank');
                } else if (text === 'Map') {
                    window.open("https://www.google.com/maps/search/" + searchText, '_blank');
                } else if (text === 'Translate') {
                    window.open("https://translate.google.com/?sl=auto&tl=en&text=" + searchText, '_blank');
                } else if (text === 'News') {
                    window.open("https://www.google.com/search?tbm=nws&q=" + searchText, '_blank');
                }
                }
            }

            container.appendChild(button);
        }
        createButton('Web');
        createButton('Images');
        createButton('Videos');
        createButton('Map');
        createButton('Translate');
        createButton('News');

        // Replace the object with the container
        object.parentNode.replaceChild(container, object);

    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址