From 60930c4f1a56c10493828956011a3e80f7af2e89 Mon Sep 17 00:00:00 2001 From: Greg Date: Sat, 4 Jul 2026 23:08:10 +0300 Subject: [PATCH] extract prices from new website --- lib/extractPrice.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/extractPrice.js b/lib/extractPrice.js index c9734eb..faef371 100644 --- a/lib/extractPrice.js +++ b/lib/extractPrice.js @@ -1,13 +1,37 @@ const timeout = (duration) => new Promise((r) => setTimeout(r, duration)); +// Selectors for both old and new Kobo layouts +const PRICE_SELECTORS = [ + // Old layout (pre-2025 redesign) + ".primary-right-container .pricing-details .active-price span", + // New layout (Tailwind, data-testid based) + '[data-testid="price"] .text-title-m-bold', +]; + +const findPrice = (page) => { + for (const sel of PRICE_SELECTORS) { + const el = page?.querySelector(sel); + if (el?.textContent?.trim()) { + return el.textContent.trim(); + } + } + return null; +}; + const observePriceOnPage = (page) => new Promise((res, rej) => { timeout(5000).then(() => rej("price not found")); - var observer = new MutationObserver(() => { - const price = page?.querySelector( - ".primary-right-container .pricing-details .active-price span", - )?.textContent; + // Check immediately first + const immediate = findPrice(page); + if (immediate) { + l("found price (immediate)", immediate); + res(immediate); + return; + } + + const observer = new MutationObserver(() => { + const price = findPrice(page); if (price) { l("found price", price);