Created
November 26, 2025 11:22
-
-
Save NoNormalCreeper/5d47d0909f2c6c7683b5b5160294f37a to your computer and use it in GitHub Desktop.
A Userscript to enhance Google AI Studio by modifying the monospaced font and customizing the browser tab title.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Google AI Studio 增强脚本 (等宽字体 + 标题同步) | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.1 | |
| // @description 集合了两个功能:1. 将 code 元素改为 Fira Code;2. 将浏览器标签页标题自动修改为当前对话标题。 | |
| // @author Rikka | |
| // @match https://aistudio.google.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com | |
| // @grant GM_addStyle | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| // ========================================== | |
| // 功能一:设置等宽字体 (Fira Code) | |
| // ========================================== | |
| GM_addStyle(` | |
| code { | |
| font-family: 'Fira Code', monospace !important; | |
| } | |
| `); | |
| // ========================================== | |
| // 功能二:自动同步页面标题 | |
| // ========================================== | |
| // 配置:目标元素的选择器 (h1 标签且包含 mode-title 类) | |
| const TITLE_SELECTOR = 'h1.mode-title'; | |
| /** | |
| * 执行修改标题的逻辑 | |
| */ | |
| function syncTitle() { | |
| const titleElement = document.querySelector(TITLE_SELECTOR); | |
| if (titleElement) { | |
| // 获取 h1 的纯文本内容并去除首尾空格 | |
| const newTitle = titleElement.textContent.trim(); | |
| // 只有当当前网页标题与 h1 内容不一致时才修改,避免死循环 | |
| // 现在的逻辑是:标题 + 后缀 | |
| const targetTitle = newTitle + " - Google AI Studio"; | |
| if (newTitle && document.title !== targetTitle) { | |
| document.title = targetTitle; | |
| } | |
| } | |
| } | |
| /** | |
| * 初始化观察者 | |
| * 监听页面变化以应对单页应用(SPA)的动态加载 | |
| */ | |
| const observer = new MutationObserver((mutations) => { | |
| // 简单防抖:每次变动都尝试同步标题 | |
| syncTitle(); | |
| }); | |
| // 开始监听 body 的变化 | |
| observer.observe(document.body, { | |
| childList: true, | |
| subtree: true, | |
| characterData: true | |
| }); | |
| // 脚本加载时先尝试运行一次 | |
| syncTitle(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment