mirror of
https://github.com/primedigitaltech/azon_seeker.git
synced 2026-10-05 15:22:59 +08:00
* feat: add Amazon collection metadata and reliable sync * fix: route extension sync through configured server * chore: release extension v0.7.13 * fix: handle extension ports across BFCache navigation * fix: classify bottom Sponsored Brands video placements * fix: exclude hidden Amazon ad cards * fix: derive Amazon result page from URL * fix: ignore hidden Amazon sponsored products * fix: preserve base Amazon product collection * fix: bind Amazon results to visible page * fix: classify visible Amazon ad formats * fix: wait for lazy Amazon ad modules * perf: reduce Amazon lazy-load scroll stops * fix: classify Amazon sponsored brand and video search ads Co-authored-by: Cursor <cursoragent@cursor.com> * fix: collect Shop by type thematic SP ads via redirect chains without data-asin Co-authored-by: Cursor <cursoragent@cursor.com> * fix: classify sponsored ads across new Amazon templates --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: PetrichorFun <127877748+PetrichorFun@users.noreply.github.com>
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
/** Wait until the fields required by the detail parser are available. */
|
|
export async function waitForAmazonDetailPageReady() {
|
|
const deadline = Date.now() + 20000;
|
|
const sleep = (milliseconds: number) =>
|
|
new Promise<void>((resolve) => setTimeout(resolve, milliseconds));
|
|
|
|
while (Date.now() < deadline) {
|
|
if (window.location.pathname.startsWith('/ap/signin')) {
|
|
throw new Error('Amazon 详情页需要重新登录');
|
|
}
|
|
if (document.querySelector('form[action*="validateCaptcha"], #captchacharacters')) {
|
|
throw new Error('Amazon 详情页触发了验证码');
|
|
}
|
|
|
|
const unavailable = document.querySelector<HTMLElement>(
|
|
'#availability .a-color-price, #outOfStock, #exports_desktop_qualifiedBuybox',
|
|
);
|
|
const title = document.querySelector<HTMLElement>('#title, #productTitle');
|
|
const titleReady = Boolean(title?.textContent?.trim());
|
|
if (document.readyState !== 'loading' && titleReady) {
|
|
title?.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
return true;
|
|
}
|
|
|
|
if (document.readyState !== 'loading' && unavailable) {
|
|
throw new Error('Amazon 商品当前不可用,详情标题未加载');
|
|
}
|
|
await sleep(300);
|
|
}
|
|
|
|
throw new Error('Amazon 详情标题在 20 秒内未加载完成');
|
|
}
|