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));
|
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) =>
|
const observePriceOnPage = (page) =>
|
||||||
new Promise((res, rej) => {
|
new Promise((res, rej) => {
|
||||||
timeout(5000).then(() => rej("price not found"));
|
timeout(5000).then(() => rej("price not found"));
|
||||||
|
|
||||||
var observer = new MutationObserver(() => {
|
// Check immediately first
|
||||||
const price = page?.querySelector(
|
const immediate = findPrice(page);
|
||||||
".primary-right-container .pricing-details .active-price span",
|
if (immediate) {
|
||||||
)?.textContent;
|
l("found price (immediate)", immediate);
|
||||||
|
res(immediate);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const observer = new MutationObserver(() => {
|
||||||
|
const price = findPrice(page);
|
||||||
|
|
||||||
if (price) {
|
if (price) {
|
||||||
l("found price", price);
|
l("found price", price);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue