Gemini Canvas Shared Page Optimization

Gemini Canvas shared page layout optimization, including removal of the Gemini logo in the header, Google avatar, Google "content may be unsafe" warning at the bottom, etc.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name                Gemini Canvas Shared Page Optimization
// @description        Gemini Canvas shared page layout optimization, including removal of the Gemini logo in the header, Google avatar, Google "content may be unsafe" warning at the bottom, etc.
// @name:zh-CN          Gemini Canvas 共享页面布局优化
// @description:zh-CN   Gemini Canvas 共享页面布局优化,包括删除头部gemini logo、google头像、底部google 不安全内容提示等。
// @version      1.3
// @author       Stuart.Z
// @match        https://gemini.google.com/share/*
// @grant        none
// @run-at       document-end
// @license      GPL-3.0 License
// @namespace https://greasyfork.org/users/324739
// ==/UserScript==




(function() {
    'use strict';

    // 检查是否为共享页面(不包含 side-nav-menu-button 的页面)
    const isSharedPage = () => {
        const sideNavButton = document.querySelector('side-nav-menu-button');
        return !sideNavButton;
    };

    const optimizeWidth = () => {
        // 如果不是共享页面,跳过
        if (!isSharedPage()) return;

        // 需要修改宽度的元素选择器
        const selectors = [
            'mat-sidenav-content',
            '.main-content',
            '.input-area-container',
            '.bottom-bar-container',
            '.conversation-container'
        ];

        selectors.forEach(selector => {
            const elements = document.querySelectorAll(selector);
            elements.forEach(el => {
                // 强制设置为 98%
                el.style.setProperty('width', '98%', 'important');
                el.setAttribute('data-width-optimized', 'true');
            });
        });
    };

    const removeElements = () => {
        // 如果不是共享页面,跳过
        if (!isSharedPage()) return;

        // 需要删除的元素选择器列表
        const removeSelectors = [
            '.footer.footer-desktop.ng-star-inserted',           // 1. 删除 footer
            '.right-section',                                    // 2. 删除 right-section
            '.gb_Cd[style*="display:block"]',                   // 3. 删除 gb_Cd (带特定样式)
            '.side-nav-menu-button.with-pill-ui',                // 4. 删除 side-nav-menu-button
            '.desktop-ogb-buffer'                                // 5. 删除 desktop-ogb-buffer
        ];

        removeSelectors.forEach(selector => {
            const elements = document.querySelectorAll(selector);
            elements.forEach(el => {
                if (el && el.parentNode) {
                    el.parentNode.removeChild(el);
                }
            });
        });
    };

    const runAllOptimizations = () => {
        optimizeWidth();
        removeElements();
    };

    // 防抖函数
    function debounce(fn, delay) {
        let timer;
        return function() {
            clearTimeout(timer);
            timer = setTimeout(() => fn.apply(this, arguments), delay);
        };
    }

    const debouncedOptimize = debounce(runAllOptimizations, 100);

    // 使用 MutationObserver 监听 DOM 变化
    const observer = new MutationObserver((mutations) => {
        const shouldOptimize = mutations.some(mutation => {
            return mutation.type === 'childList' ||
                   (mutation.type === 'attributes' && mutation.attributeName === 'style');
        });

        if (shouldOptimize) {
            debouncedOptimize();
        }
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: true,
        attributeFilter: ['style', 'class']
    });

    // 初始执行
    runAllOptimizations();

    // 监听路由变化(SPA 页面)
    const _pushState = history.pushState;
    history.pushState = function() {
        _pushState.apply(this, arguments);
        setTimeout(runAllOptimizations, 100);
    };

    const _replaceState = history.replaceState;
    history.replaceState = function() {
        _replaceState.apply(this, arguments);
        setTimeout(runAllOptimizations, 100);
    };

    // 监听 popstate 事件(浏览器前进后退)
    window.addEventListener('popstate', () => {
        setTimeout(runAllOptimizations, 100);
    });

})();