docs: 补充mem_scanner和web_setup SOP;优化代码风格和上下文管理

This commit is contained in:
Liang Jiaqing
2026-02-16 22:33:50 +08:00
parent dbc28fbc35
commit 67c7b3fa71
5 changed files with 62 additions and 15 deletions

View File

@@ -19,6 +19,37 @@ browser = "chrome" if shutil.which("chrome") else "msedge" # Edge内置必存
- Edge: `start "" "https://microsoftedge.microsoft.com/addons/detail/tampermonkey/iikmkjmpaadaobahmlepeloendndfphd"`
2. 提示用户点击"安装"并确认。
## 阶段 1.5:开启「允许运行用户脚本」
**前置**TM 已安装,但 Chrome 可能默认未开启此权限。
需打开 TM 的扩展详情页,手动开启相关开关。
### 自动打开详情页
1. 从文件系统读取 TM 扩展 ID
```python
import os, json, glob
ext_dir = os.path.expandvars(r'%LOCALAPPDATA%\Google\Chrome\User Data\Default\Extensions')
for eid in os.listdir(ext_dir):
for ver in glob.glob(os.path.join(ext_dir, eid, '*')):
mf = os.path.join(ver, 'manifest.json')
if os.path.isfile(mf):
with open(mf, encoding='utf-8') as f:
m = json.load(f)
if 'tampermonkey' in m.get('name','').lower() or 'tampermonkey' in m.get('description','').lower():
tm_id = eid; break
```
2. 导航到 `chrome://extensions/?id={tm_id}`
- ⚠️ `chrome://` 协议无法通过命令行参数或 JS(`window.open`) 打开
- ✅ 用 ljqCtrl需先打开一个 Chrome 窗口并置顶)或剪贴板+地址栏方案:
```python
# 剪贴板方案写入URL → Ctrl+L → Ctrl+V → Enter
import win32clipboard
win32clipboard.OpenClipboard(); win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(f'chrome://extensions/?id={tm_id}')
win32clipboard.CloseClipboard()
# 然后用 ljqCtrl 或 SendKeys 发送 Ctrl+L, Ctrl+V, Enter
```
3. 提示用户在详情页中开启「允许运行用户脚本」开关。
## 阶段二:安装 ljq_web_driver.user.js
**脚本路径**: `../assets/ljq_web_driver.user.js`