Update authorization&cartId.js
This commit is contained in:
@@ -3,10 +3,7 @@
|
|||||||
*
|
*
|
||||||
* 功能:
|
* 功能:
|
||||||
* - 保持原有:始终在 $persistentStore 中维护最新的 authorization 和 cartId
|
* - 保持原有:始终在 $persistentStore 中维护最新的 authorization 和 cartId
|
||||||
* - 新增:把每次捕获追加到 cart_records 数组(cartId 去重)
|
* - 把每次捕获追加到 cart_records 数组(cartId 去重)
|
||||||
*
|
|
||||||
* cart_records 结构:[{cartId, authorization, ts}, ...]
|
|
||||||
* - 匹配由网页脚本动态完成,本脚本不做任何配对
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const pattern = /^https:\/\/cart\.production\.store-web\.dynamics\.com\/v1\.0\/Cart\/eligibilityCheck\?/;
|
const pattern = /^https:\/\/cart\.production\.store-web\.dynamics\.com\/v1\.0\/Cart\/eligibilityCheck\?/;
|
||||||
@@ -21,7 +18,6 @@ if ($request.method === "PUT" && pattern.test(url)) {
|
|||||||
const cartId = urlObj.searchParams.get('cartId');
|
const cartId = urlObj.searchParams.get('cartId');
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
// 保留原有:维护最新二元组
|
|
||||||
if (authorization && authorization !== $persistentStore.read("authorization")) {
|
if (authorization && authorization !== $persistentStore.read("authorization")) {
|
||||||
$persistentStore.write(authorization, "authorization");
|
$persistentStore.write(authorization, "authorization");
|
||||||
console.log(`Stored authorization: ${authorization}`);
|
console.log(`Stored authorization: ${authorization}`);
|
||||||
@@ -31,22 +27,17 @@ if ($request.method === "PUT" && pattern.test(url)) {
|
|||||||
console.log(`Stored cartId: ${cartId}`);
|
console.log(`Stored cartId: ${cartId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增:追加到 cart_records(cartId 去重)
|
|
||||||
if (cartId && authorization) {
|
if (cartId && authorization) {
|
||||||
appendCartRecord({ cartId, authorization, ts: now });
|
appendCartRecord({ cartId, authorization, ts: now });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保留原始的这条通知
|
||||||
$notification.post(
|
$notification.post(
|
||||||
"Surge 信息存储",
|
"Surge 信息存储",
|
||||||
"已捕获并存储 authorization 和 cartId"
|
"已捕获并存储 authorization 和 cartId"
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Error capturing authorization & cartId: ${error}`);
|
console.log(`Error capturing authorization & cartId: ${error}`);
|
||||||
$notification.post(
|
|
||||||
"Surge 脚本错误",
|
|
||||||
"无法捕获 authorization 和 cartId",
|
|
||||||
`${error}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +51,6 @@ function appendCartRecord(entry) {
|
|||||||
} catch (e) { records = []; }
|
} catch (e) { records = []; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去重:相同 cartId 不重复记录
|
|
||||||
if (records.some(r => r.cartId === entry.cartId)) {
|
if (records.some(r => r.cartId === entry.cartId)) {
|
||||||
console.log(`[cart] SKIP: cartId=${entry.cartId} 已存在`);
|
console.log(`[cart] SKIP: cartId=${entry.cartId} 已存在`);
|
||||||
return;
|
return;
|
||||||
@@ -71,7 +61,6 @@ function appendCartRecord(entry) {
|
|||||||
$persistentStore.write(JSON.stringify(records), "cart_records");
|
$persistentStore.write(JSON.stringify(records), "cart_records");
|
||||||
|
|
||||||
console.log(`[cart] ✅ 已记录 cartId=${entry.cartId}, total=${records.length}`);
|
console.log(`[cart] ✅ 已记录 cartId=${entry.cartId}, total=${records.length}`);
|
||||||
$notification.post("Surge 历史记录", "已记录 cart 信息", "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$done({});
|
$done({});
|
||||||
|
|||||||
Reference in New Issue
Block a user