extract prices from new website
This commit is contained in:
parent
982800821b
commit
60930c4f1a
1 changed files with 28 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue