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:
jtricerolph 2026-07-14 17:49:27 +00:00
parent e481ad5258
commit 69ecf1012e
4 changed files with 110 additions and 4 deletions

View file

@ -107,13 +107,26 @@ _EXTRACT_RATES_JS = """
let fltrs = {}; let fltrs = {};
try { fltrs = JSON.parse(tr.getAttribute('data-fltrs') || '{}'); } catch(e) {} 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 cells = tr.querySelectorAll('td');
const condCell = cells.length >= 3 ? cells[2].innerText || '' : '';
const breakfastIncluded = condCell.toLowerCase().includes('breakfast'); // 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); 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 cancelMatch = condCell.match(/free cancellation before ([\\w\\s]+)/i);
const freeCancelText = cancelMatch ? cancelMatch[1].trim() : null; const freeCancelText = cancelMatch ? cancelMatch[1].trim() : null;

View file

@ -1,5 +1,7 @@
import { Routes, Route, Navigate } from 'react-router-dom' import { Routes, Route, Navigate } from 'react-router-dom'
import AuthGate from './components/AuthGate' import AuthGate from './components/AuthGate'
import { UpdateBanner } from './components/UpdateBanner'
import { useVersionCheck } from './hooks/useVersionCheck'
import Layout from './components/Layout' import Layout from './components/Layout'
import Bookability from './pages/Bookability' import Bookability from './pages/Bookability'
import MarketView from './pages/MarketView' import MarketView from './pages/MarketView'
@ -8,7 +10,9 @@ import RateAnalysis from './pages/RateAnalysis'
import Settings from './pages/Settings' import Settings from './pages/Settings'
export default function App() { export default function App() {
const updateAvailable = useVersionCheck('/rates/health')
return ( return (
<>
<AuthGate> <AuthGate>
<Layout> <Layout>
<Routes> <Routes>
@ -24,5 +28,7 @@ export default function App() {
</Routes> </Routes>
</Layout> </Layout>
</AuthGate> </AuthGate>
<UpdateBanner visible={updateAvailable} />
</>
) )
} }

View file

@ -0,0 +1,44 @@
import { RefreshCw } from 'lucide-react'
export function UpdateBanner({ visible }: { visible: boolean }) {
if (!visible) return null
return (
<div style={{
position: 'fixed',
bottom: 0,
left: 0,
right: 0,
zIndex: 9999,
background: 'var(--sidebar)',
color: 'var(--text-light)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '10px 16px',
fontSize: '14px',
boxShadow: '0 -2px 8px rgba(0,0,0,0.3)',
}}>
<span>A new version is available.</span>
<button
onClick={() => window.location.reload()}
style={{
display: 'flex',
alignItems: 'center',
gap: '6px',
background: 'var(--accent)',
color: 'var(--sidebar)',
border: 'none',
borderRadius: '4px',
padding: '6px 14px',
fontWeight: 600,
cursor: 'pointer',
fontSize: '13px',
}}
>
<RefreshCw size={14} strokeWidth={1.75} />
Reload
</button>
</div>
)
}

View file

@ -0,0 +1,43 @@
import { useEffect, useState } from 'react'
const POLL_MS = 2 * 60 * 1000
export function useVersionCheck(healthUrl: string) {
const [updateAvailable, setUpdateAvailable] = useState(false)
useEffect(() => {
let seenVersion: string | null = null
async function check() {
try {
const res = await fetch(healthUrl, { cache: 'no-store' })
if (!res.ok) return
const data = await res.json()
const v: string | undefined = data.version
if (!v) return
if (seenVersion === null) {
seenVersion = v
} else if (v !== seenVersion) {
setUpdateAvailable(true)
}
} catch {
// network error — skip silently
}
}
check()
const interval = setInterval(check, POLL_MS)
function onVisible() {
if (document.visibilityState === 'visible') check()
}
document.addEventListener('visibilitychange', onVisible)
return () => {
clearInterval(interval)
document.removeEventListener('visibilitychange', onVisible)
}
}, [healthUrl])
return updateAvailable
}