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);