From 1eab195bbd66e143337dba5c145ab3d630f51be1 Mon Sep 17 00:00:00 2001 From: XXhaos Date: Thu, 30 Apr 2026 13:19:13 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Scripts/nodeseek.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/nodeseek.js | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Scripts/nodeseek.js b/Scripts/nodeseek.js index 621590a..900c6e3 100644 --- a/Scripts/nodeseek.js +++ b/Scripts/nodeseek.js @@ -380,29 +380,36 @@ function ObjectKeys2LowerCase(obj) { } /* ====================== 入口 ====================== */ -const SCRIPT_VERSION = "v3-debug-2026-04-30"; +const SCRIPT_VERSION = "v5-url-based"; !(async () => { try { - // 版本标记 + 环境诊断(解决 "cron 误入抓 cookie 分支" 问题用) - $.log(`[VERSION] ${SCRIPT_VERSION}`); - $.log(`[ENV] $request=${typeof $request}, $response=${typeof $response}, $argument=${typeof $argument}`); - if (typeof $request !== "undefined" && $request) { - $.log(`[ENV] $request keys: ${Object.keys($request || {}).join(",")}`); - $.log(`[ENV] $request.url: ${$request.url || ""}`); - } - if (typeof $response !== "undefined" && $response) { - $.log(`[ENV] $response keys: ${Object.keys($response || {}).join(",")}`); - $.log(`[ENV] $response.body length: ${$response.body ? $response.body.length : ""}`); - } + $.log(`\n========== 🚀 ${SCRIPT_VERSION} 已加载 ==========\n`); - // 判断运行模式: - // - http-response 脚本:$response 存在(含 body)→ 抓 cookie - // - cron / 手动执行 / Node.js:$response 不存在 → 签到 - // 不能用 $request 判断,因为某些 Surge 版本在 cron 里也会注入 $request - const isMitmMode = - typeof $response !== "undefined" && $response && $response.body; - $.log(`[ENV] isMitmMode=${isMitmMode}`); + // 模式判断:基于 $request.url 是否真的指向 nodeseek 的 getInfo API + // + // 背景:Surge 在手动运行 cron 脚本时,会注入一个 mock 的 $request/$response + // 上下文($request.url 通常是 http://www.apple.com/, + // $response.body 是 {"foo":"bar"})。所以单纯用 typeof 判断 + // 全局变量是否存在不可靠。 + // + // 真实分支: + // - MITM 触发:$request.url = https://www.nodeseek.com/api/account/getInfo/?... + // - cron / 手动执行:$request.url 是 mock 值,不含 nodeseek 域名 + // - Node.js:$request 不存在 + const reqUrl = + typeof $request !== "undefined" && + $request && + typeof $request.url === "string" + ? $request.url + : ""; + const isMitmMode = reqUrl.includes("nodeseek.com/api/account/getInfo"); + + $.log( + `[mode] $request.url="${reqUrl || ""}" → ${ + isMitmMode ? "抓cookie" : "签到" + }` + ); if (isMitmMode) { await getCookie();