Fix breakfast detection on hotel-page scraper + add update banner
Breakfast was keyed off cells[2] specifically; hotel page templates vary and the conditions column can appear at a different index, causing breakfast_included to always be false for own/competitor rates. Now scans full row innerText and also checks data-fltrs.mealplan/breakfast_included as a secondary signal. Free cancellation extraction similarly updated to search all cells rather than assuming a fixed column. Also ships the update-available banner (polls /health every 2 min, prompts reload when the version hash changes after a deploy). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e481ad5258
commit
69ecf1012e
4 changed files with 110 additions and 4 deletions
|
|
@ -107,12 +107,25 @@ _EXTRACT_RATES_JS = """
|
|||
let fltrs = {};
|
||||
try { fltrs = JSON.parse(tr.getAttribute('data-fltrs') || '{}'); } catch(e) {}
|
||||
|
||||
// Conditions cell (3rd <td>) holds meal plan + cancel info
|
||||
const cells = tr.querySelectorAll('td');
|
||||
const condCell = cells.length >= 3 ? cells[2].innerText || '' : '';
|
||||
|
||||
const breakfastIncluded = condCell.toLowerCase().includes('breakfast');
|
||||
const nonRefundable = (fltrs.non_refundable === 1);
|
||||
// Scan ALL cells for breakfast — the conditions column index varies
|
||||
// across hotel page templates (some hotels swap occupancy + conditions).
|
||||
// Also check data-fltrs which carries a mealplan flag on some properties.
|
||||
const rowText = (tr.innerText || '').toLowerCase();
|
||||
const breakfastIncluded = rowText.includes('breakfast')
|
||||
|| fltrs.mealplan === 1
|
||||
|| fltrs.breakfast_included === 1;
|
||||
|
||||
const nonRefundable = (fltrs.non_refundable === 1);
|
||||
|
||||
// Cancellation text: find whichever cell mentions it.
|
||||
let condCell = '';
|
||||
for (const cell of cells) {
|
||||
const t = cell.innerText || '';
|
||||
if (t.toLowerCase().includes('free cancellation')) { condCell = t; break; }
|
||||
}
|
||||
if (!condCell && cells.length >= 3) condCell = cells[2].innerText || '';
|
||||
|
||||
const cancelMatch = condCell.match(/free cancellation before ([\\w\\s]+)/i);
|
||||
const freeCancelText = cancelMatch ? cancelMatch[1].trim() : null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue