feat(gemini-ops): 新增登录状态检查功能,支持检测是否已登录 Google 账号
This commit is contained in:
@@ -921,4 +921,28 @@ function isImageLoaded(op) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否已登录 Google 账号
|
||||
*
|
||||
* 判断依据:顶部导航栏 div.boqOnegoogleliteOgbOneGoogleBar 的 innerText
|
||||
* 包含"登录"或"sign in"(不区分大小写)则视为未登录
|
||||
*
|
||||
* @param {ReturnType<typeof createOperator>} op
|
||||
* @returns {Promise<{ok: boolean, loggedIn: boolean, barText?: string, error?: string}>}
|
||||
*/
|
||||
function isLoggedIn(op) {
|
||||
return op.query(() => {
|
||||
const bar = document.querySelector('div.boqOnegoogleliteOgbOneGoogleBar');
|
||||
if (!bar) {
|
||||
return { ok: false, loggedIn: false, error: 'login_bar_not_found' };
|
||||
}
|
||||
|
||||
const text = (bar.innerText || '').trim();
|
||||
const lower = text.toLowerCase();
|
||||
const notLoggedIn = lower.includes('登录') || lower.includes('sign in');
|
||||
|
||||
return { ok: true, loggedIn: !notLoggedIn, barText: text };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -374,6 +374,34 @@ server.registerTool(
|
||||
}
|
||||
);
|
||||
|
||||
// ─── 登录状态检查 ───
|
||||
|
||||
server.registerTool(
|
||||
"gemini_check_login",
|
||||
{
|
||||
description: "检查当前 Gemini 页面是否已登录 Google 账号",
|
||||
inputSchema: {},
|
||||
},
|
||||
async () => {
|
||||
try {
|
||||
const { ops } = await createGeminiSession();
|
||||
const result = await ops.checkLogin();
|
||||
disconnect();
|
||||
|
||||
if (!result.ok) {
|
||||
return { content: [{ type: "text", text: `检测失败: ${result.error}` }], isError: true };
|
||||
}
|
||||
|
||||
const status = result.loggedIn ? "已登录" : "未登录";
|
||||
return {
|
||||
content: [{ type: "text", text: `${status}(导航栏文本: "${result.barText}")` }],
|
||||
};
|
||||
} catch (err) {
|
||||
return { content: [{ type: "text", text: `执行崩溃: ${err.message}` }], isError: true };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// ─── 页面状态 & 恢复 ───
|
||||
|
||||
server.registerTool(
|
||||
|
||||
Reference in New Issue
Block a user