eATM

修改chatGPT for google在网页中的位置

 

// ==UserScript==
// @name         chatGPT UI修改
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.google.com.hk/search?*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com.hk
// @grant        none
// ==/UserScript==

(function ()
{
    'use strict';

    //过滤广告
    var filterAd = function ()
    {
        let observer2 = new MutationObserver((mutations) =>
        {
            mutations.forEach((mutation) =>
            {
                // 检查是否有chat-gpt-for-google-search-enhance元素被添加到rhs中
                if (mutation.addedNodes) {
                    mutation.addedNodes.forEach((node) =>
                    {
                        if (node.tagName == "A") {
                            console.log("过滤广告");
                            node.style.display="none"
                            observer2.disconnect();          //停止观察
                        }
                    });
                }
            });
        });

        let config = { childList: true, subtree: true };  // 配置观察选项

        try {
            observer2.observe(document.querySelector("#chat-gpt-for-google-search-enhance").shadowRoot.querySelector("div"), config);                // 开始观察
        } catch (error) {
            setTimeout(filterAd, 50);
        }
    }

    let moveElement = function (is_init, is_sleep)
    {
        let chatElement = document.getElementById("chat-gpt-for-google-search-enhance");
        if (!chatElement) {
            return false;
        }

        if (!is_sleep) {
            console.log("第一次进入");
            setTimeout(moveElement, 50, is_init, true);
            return true;
        }

        const centerCol = document.getElementById('center_col');
        centerCol.insertBefore(chatElement, centerCol.firstChild);

        var setChatGPTStyle;
        setChatGPTStyle = function ()
        {
            try {

                chatElement.style.marginLeft = "0px";

                let chatgpt = document.querySelector("#chat-gpt-for-google-search-enhance").shadowRoot.querySelector(".search-enhance-WDIEk");
                chatgpt.style.width = "auto";
                console.log("设置成功了");
            } catch (error) {
                console.log("出错了");
                setTimeout(setChatGPTStyle, 100);
            }
        }
        setTimeout(setChatGPTStyle, 50);

        filterAd();

        return true;
    }

    if (!moveElement(true)) {
        let observer = new MutationObserver((mutations) =>
        {
            mutations.forEach((mutation) =>
            {
                // 检查是否有chat-gpt-for-google-search-enhance元素被添加到rhs中
                if (mutation.addedNodes) {
                    mutation.addedNodes.forEach((node) =>
                    {
                        if (node.id === 'chat-gpt-for-google-search-enhance') {

                            moveElement(false);

                            observer.disconnect();          //停止观察
                        }
                    });
                }
            });
        });

        const config = { childList: true, subtree: true };  // 配置观察选项

        observer.observe(document.body, config);                // 开始观察
    }




})();

 

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注