Files
SkyJourneyandClaude Sonnet 5 634d38d414 fix: 修复一键安装命令在 irm|iex 场景下的 BOM 报错
install.ps1 为兼容 Windows PowerShell 5.1 的 -File 加载场景带有 UTF-8 BOM,
但 irm 拉取内容再交给 iex 执行时不会自动剥离 BOM 字节,导致其被解码为字符串
里的 U+FEFF 字符,紧贴首行注释符 # 被解析器当作未知命令,报错但不影响最终结果。
改为先 TrimStart([char]0xFEFF) 再 iex,兼容 PS 5.1 和 PS 7。同时把 Windows
一节标题和说明明确标注 PowerShell,避免有人用 cmd 执行。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTuSGDEryaM7BUop9wNni9
2026-08-18 09:14:32 +08:00

93 lines
3.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Gemini in Chrome
> Fork 自:[appsail/Gemini-in-Chrome](https://github.com/appsail/Gemini-in-Chrome)MIT License
一键脚本,用于强制启用 Chrome 内置的 Gemini AI 功能(绕过非美区的资格限制)。
基于上述原项目重写,修复了原脚本"字段不存在时静默不生效"的问题,改为 JSON 感知读写
`jq` 优先,装不上时自动降级为 `sed`+`awk` 零依赖兜底方案),并支持同一台机器上的
多个 Chrome 账号(profile)。
## 快速开始
### macOS / Linux
```bash
curl -fsSL https://gitea.rk-health.com/jiangshunzhi/Gemini-in-Chrome/raw/branch/main/install.sh | bash
```
### WindowsPowerShell
打开 PowerShell(不是 cmd)执行:
```powershell
iex ((irm https://gitea.rk-health.com/jiangshunzhi/Gemini-in-Chrome/raw/branch/main/install.ps1).TrimStart([char]0xFEFF))
```
## 脚本做了什么
1. ✅ 检查 Chrome 是否在运行(在运行的话会提示你先完全退出——Local State 会在 Chrome 退出时被覆写,不退出改了也白改)
2. 💾 备份原配置文件(`Local State.bak`
3. 🔧 修补以下字段(存在则替换、不存在则插入,而不是原脚本那种"只替换已存在字段"的逻辑):
- 顶层 `variations_country``"us"`
- 顶层 `variations_permanent_consistency_country``[当前 Chrome 版本号, "us"]`
- `profile.info_cache` 下**每一个** profile 的 `is_glic_eligible``true`(不只是已存在该字段的那个)
4. ✓ 写回前后都做合法性校验,`sed`+`awk` 兜底路径下用括号配平检查兜底;校验不过就自动放弃改动,不会覆盖原文件
5. ✓ 汇报本次实际用的是 `jq` 路径还是 `sed`+`awk` 兜底路径,以及各字段是否生效
## 还原原始配置
**macOS**
```bash
mv ~/Library/Application\ Support/Google/Chrome/Local\ State.bak \
~/Library/Application\ Support/Google/Chrome/Local\ State
```
**Linux**
```bash
mv ~/.config/google-chrome/Local\ State.bak \
~/.config/google-chrome/Local\ State
```
**Windows PowerShell**
```powershell
Move-Item -Path "$env:LOCALAPPDATA\Google\Chrome\User Data\Local State.bak" `
-Destination "$env:LOCALAPPDATA\Google\Chrome\User Data\Local State" -Force
```
## 安全性
- 改动前一定会先备份原配置
- 只改本地 Chrome 配置,不上传任何数据、不访问网络(除了下载脚本本身,以及 `jq` 缺失时按需自动安装)
- 改动前后都做合法性校验,写坏了会自动回滚、不覆盖原文件
- 随时可还原
- 非官方脚本,仅供个人研究/自用,风险自负
## jq 依赖说明
macOS 上如果检测到 `jq` 就直接用;没有的话,检测到 Homebrew 会尝试 `brew install jq`
没有 Homebrew 就直接走零依赖兜底,不会替你装 Homebrew。
Linux 上会按顺序探测 `apt-get`/`dnf`/`yum`/`pacman`/`apk` 并尝试自动安装(可能会弹 `sudo`
密码提示);装不上(比如设备网络受限)同样自动降级为 `sed`+`awk` 方案。
`install.ps1`Windows)用 PowerShell 原生的 `ConvertFrom-Json`/`ConvertTo-Json`,本身就不
依赖 `jq`
## 配置文件路径
| 系统 | 路径 |
|----|------|
| macOS | `~/Library/Application Support/Google/Chrome/Local State` |
| Linux | `~/.config/google-chrome/Local State` |
| Windows | `%LOCALAPPDATA%\Google\Chrome\User Data\Local State` |
## 测试
`test-fixtures/` 下有一份完全人工构造(非真实账号脱敏)的多 profile 测试样本,
覆盖了"字段缺失 / 已是 false / 已是 true"三种场景,用法见该目录下的 README。
## License
MIT,见 [LICENSE](./LICENSE)。基于 [appsail/Gemini-in-Chrome](https://github.com/appsail/Gemini-in-Chrome) 重写。