// ==UserScript== // @name Gemini 內文寬屏神器 (Final Release) // @namespace http://tampermonkey.net/ // @version 11.0 // @description 解除 Google Gemini 對話框的寬度限制,將使用者對話強制靠右並擴展至 90% 寬度,同時保持 AI 回答滿版,提供最佳閱讀體驗。 // @author Gemini User // @match https://gemini.google.com/* // @grant GM_addStyle // @downloadURL https://update.greasyfork.icu/scripts/559460/Gemini%20%E5%85%A7%E6%96%87%E5%AF%AC%E5%B1%8F%E7%A5%9E%E5%99%A8%20%28Final%20Release%29.user.js // @updateURL https://update.greasyfork.icu/scripts/559460/Gemini%20%E5%85%A7%E6%96%87%E5%AF%AC%E5%B1%8F%E7%A5%9E%E5%99%A8%20%28Final%20Release%29.meta.js // ==/UserScript== (function() { 'use strict'; // === 1. 基礎 CSS 設定 === const css = ` /* 1. 強制長字串換行,防止撐破版面 */ .query-text-line, p, div, span { overflow-wrap: anywhere !important; word-break: break-all !important; } /* 2. 輸入框保護:限制最大寬度並置中,避免過寬難以閱讀 */ div[class*="input-area"], div[class*="bottom-bar"] { max-width: 900px !important; margin: 0 auto !important; } /* 3. 側邊欄層級保護:確保永遠在最上層可點擊 */ mat-sidenav { z-index: 9999 !important; } `; const style = document.createElement('style'); style.textContent = css; document.head.appendChild(style); // === 2. 核心邏輯:層層破防 === function fixLayout() { // 鎖定使用者輸入的文字行 const textLines = document.querySelectorAll('.query-text-line'); textLines.forEach(text => { let current = text; let bubble = null; // 往上遍歷 10 層父容器 (寧可殺錯,不可放過) for (let i = 0; i < 10; i++) { if (!current.parentElement) break; current = current.parentElement; const tagName = current.tagName; // --- A. 尋找氣泡本體 --- // 通常氣泡會有背景色,或者包含特定 class if (!bubble) { const style = window.getComputedStyle(current); if ((style.backgroundColor !== 'rgba(0, 0, 0, 0)' && style.backgroundColor !== 'transparent') || current.classList.contains('user-query-container')) { bubble = current; } } // --- B. 解除寬度限制 --- // 只要不是最外層的系統框架,全部強制設為 100% 寬 if (tagName !== 'BODY' && tagName !== 'HTML' && tagName !== 'MAIN' && tagName !== 'MAT-SIDENAV-CONTENT') { current.style.maxWidth = 'none'; current.style.width = '100%'; current.style.marginLeft = '0'; current.style.marginRight = '0'; current.style.paddingLeft = '0'; current.style.paddingRight = '0'; current.style.alignItems = 'stretch'; // 針對 Flex 容器 } } // --- C. 使用者氣泡整形 --- if (bubble) { // 設定氣泡樣式:靠右 + 90% 寬 bubble.style.width = 'auto'; bubble.style.maxWidth = '90%'; bubble.style.minWidth = '50%'; // 強制推向右邊 bubble.style.marginLeft = 'auto'; bubble.style.marginRight = '20px'; // 右側留白 // 顯示設定 bubble.style.display = 'block'; bubble.style.borderRadius = '12px'; // 確保氣泡的父容器也允許靠右排列 if (bubble.parentElement) { bubble.parentElement.style.display = 'flex'; bubble.parentElement.style.flexDirection = 'column'; bubble.parentElement.style.alignItems = 'flex-end'; } } }); } // === 3. 執行 === // 每 1 秒檢查一次,確保新產生的對話也能即時生效 setInterval(fixLayout, 1000); })();