# Wife Radar (PAL Flight Note)

A small "sticky note" app for following a **Philippine Airlines** flight: where the plane is, how much of the flight is done, and when it lands, in **Philippine time (PH)** and **Vancouver time (MST)** only.

I built it to follow someone in my family who flies with PAL as cabin crew. Her roster shows flight numbers, not where the plane is, and the two time zones are always confusing. Now I type the flight number (or paste her roster screenshot) and the note does the rest.

- **Live:** [itsnico.pages.dev/pal](https://itsnico.pages.dev/pal/)
- **On my desktop:** a shortcut opens this same page as a small app window
- **On a phone:** "Add to Home Screen" installs it like an app

---

## Key highlights

- **Type a flight number, that's it.** `116` is enough. The route comes from a list of all 540 PAL flights, and the takeoff and landing times now fill in by themselves.
- **Real times, delays included.** Scheduled takeoff and landing come from PAL's published timetable (via AeroDataBox). About 4 hours before takeoff it checks again and shows "running 40m late" if PAL moved the time, or a note if the flight is cancelled.
- **Live position on a map.** Where the plane is right now, % flown, time until landing, and "942 km from Tokyo".
- **Only two clocks.** Every time is shown in Philippine time (blue) and Vancouver time (orange), never "local".
- **Works over the ocean.** When the plane is out of range, it keeps estimating her position from the last signal.
- **Private.** Saved flights stay in your own browser; nobody else visiting the page sees them.
- **Free to run.** Every data source is free; the only account needed is a free AeroDataBox key.

## Where the data comes from: before and now

Two different kinds of data answer two different questions:

- **adsb.lol answers "where is the plane right now?"** Planes broadcast their position over radio, volunteers with receivers pick it up, and adsb.lol shares it. It is the *real* flight, but it only knows the present: before takeoff, or over the open ocean, it has nothing.
- **AeroDataBox answers "when is the flight supposed to leave and land?"** It holds the airline's *timetable*, so it knows the times days ahead, before the plane has even moved, and it picks up PAL's updates (delays, cancellations).

| Question | Before | Now |
|---|---|---|
| Where is the plane? | adsb.lol (live) | adsb.lol (live), unchanged |
| When does it take off and land? | Nothing automatic: read from her roster screenshot, typed in by hand, or learned by watching the same flight number fly once | **AeroDataBox fills it in automatically** from the flight number and date. The roster, typing and learned times still work and still win if present |
| Is it late or cancelled? | Only visible once the plane did (or didn't) move on the live feed | AeroDataBox shows PAL's revised time ("running 40m late") and cancellations before takeoff |
| Which PAL flights are flying now? | OpenSky + adsb.lol | adsb.lol around 8 PAL airports (OpenSky never answered from the website) |

In short: **before**, the tracker knew *where* she was but had to be told *when* her flight was. **Now** it knows both: the timetable from AeroDataBox and the reality from adsb.lol.

---

## What it does

### Three pages
| Page | What's on it |
|---|---|
| **Now** | Status headline ("She's in the air.", "Departs in 3h 10m.", "Landed in Vancouver."), **% flown**, **time until landing**, landing time in PH and MST, and two postcards with each country's flag joined by the flight path |
| **Map** | Full live map with the great-circle route and the plane |
| **Trip** | Her duty day (check-in → takeoff → landing → off duty), layovers, all saved flights, adding flights, notification switch |

### Adding a flight
1. **Search by flight number.** Type `116`, `PR116` or `PAL116`. Every PAL flight number (540) is in the list with its route, so `PR116 · Manila → Vancouver` appears straight away. The date defaults to *today in the departure city* (Manila is usually already tomorrow).
2. **"Seen right now" buttons.** PAL flights that are in the air (green) or on the ground (grey) at the moment, tap one to pick it.
3. **Paste a roster screenshot** (Ctrl+V or drag and drop). OCR reads the flight number, date, airports, times, aircraft registration and the duty line (`19:35~19:00` = check-in and off duty). Several flights on one screenshot are all added.

4. **Open a share link.** `…/pal/?f=PR116&d=2026-11-11` opens with that flight already added. Every flight card has a Share button that makes one.

Times fill in automatically from AeroDataBox (see above). If a time is ever missing, the note still works: it waits for the plane's live signal, and once it has times you also get countdowns and estimates over the ocean.

**It learns the times itself.** When it watches a flight leave the ground and touch down, it remembers both moments. They fill in the Departs / Lands boxes, and the next time the same flight number is added it starts with those "usual" times.

### Where the plane is (in order of trust)
1. **Live** ADS-B position from [adsb.lol](https://adsb.lol), checked every minute while the plane is visible and every 3 minutes otherwise (to fit adsb.lol's free daily limit).
2. **Dead reckoning** when the plane is out of receiver range (mid-Pacific): it continues along the great circle from the last signal at the last known speed.
3. **Schedule estimate** when there's no signal yet: position along the route by elapsed time.

### Other details
- **Only two clocks, colour-coded everywhere:** blue **PH**, orange **MST**. Vancouver's time zone comes from the browser's time-zone data, so it follows whatever BC actually uses.
- **"942 km from Tokyo":** distance to the destination under the headline while she's in the air.
- **Notifications** at takeoff and landing while the page is open (even in the background).
- **Mini window** that stays on top of other windows (Document Picture-in-Picture), with a % ring and the landing time.
- **Responsive:** phone, tablet and desktop. Wide screens get two columns on Trip; Now always stays one vertical column.
- **Private by design:** saved flights live only in your own browser (`localStorage`). Nobody else visiting the page sees them.

---

## How it's built

One HTML file, no framework, no build step.

```
pal/
  index.html          the whole app (HTML + CSS + JS)
  pal-routes.json     every PAL flight number → route, plus airport positions and countries
  manifest.webmanifest, icon-*.png   make it installable ("Add to Home Screen")
  README.md           this file
functions/pal/api/
  callsign/[cs].js    live position: passes adsb.lol through (no CORS headers), shared for 30 s, one retry
  times.js            scheduled + revised takeoff/landing from AeroDataBox (key kept in Cloudflare), cached 6 h
  pal-live.js         PAL flights visible now: adsb.lol around 8 PAL airports, cached 10 min
```

| Piece | Source | Notes |
|---|---|---|
| Live positions | [adsb.lol](https://adsb.lol) | Free, no key, **500 lookups a day per address**. Needs a small server-side pass-through because of CORS |
| Scheduled times | [AeroDataBox](https://aerodatabox.com) via RapidAPI | Free Basic plan, 400 units a month, 2 per lookup. Key stored as the Cloudflare secret `AERODATABOX_KEY` |
| "Seen right now" list | adsb.lol | Looks 250 nm around 8 PAL airports. OpenSky was dropped: it never answers Cloudflare and made the list wait ~20 s |
| Routes and airports | [vradarserver/standing-data](https://github.com/vradarserver/standing-data) | Open route database: 540 PAL flights, 79 airports |
| Roster OCR | [Tesseract.js](https://tesseract.projectnaptha.com/) | Runs in the browser. Grayscale preprocessing made the grey-on-blue roster text unreadable, so the image is only upscaled 2× |
| Map | [Leaflet](https://leafletjs.com) + OpenStreetMap tiles | Route drawn as a great circle, unwrapped across the date line |
| Flags | [flagcdn.com](https://flagcdn.com) | Real proportions (PH 2:1, JP 3:2, QA long and thin) |

The two `functions/` files run as Cloudflare Pages Functions. The first version ran from a small Python server on my PC; that was retired once the website could do everything it did.

**Scheduled times.** When a flight is added without times, the tracker asks AeroDataBox for that day's scheduled and revised takeoff and landing (once when added, once more about 4 hours before takeoff to catch delays). Times from her roster or typed in always win. Without the key, times come from her roster, are typed in, or are learned from flights the note has watched.

---

## How it got here (build log)

1. **First version:** a yellow sticky note. Paste a roster screenshot → OCR → track the flight. Live position from adsb.lol, dead reckoning over the Pacific, schedule fallback. A Python server because adsb.lol blocks direct browser calls.
2. **Redesign:** a design canvas of five screens (in the air, before takeoff, landed + layover, mini mode, trip roster), then the chosen one built into the app: paper "postcards", stamps, a pin and paperclip, and a dashed route with her position on it.
3. **PH and MST only:** every time on the page is shown in both, colour-coded, never "local".
4. **Bigger numbers:** % flown and time to landing became the largest text on the page.
5. **Duty times from the roster** (check-in / off duty), **notifications**, **mini window**, **trip roster** with layovers.
6. **Bug fixed:** a Manila departure after midnight lands in Vancouver on the *previous* calendar day; arrivals were being pushed a day late. Arrival is now the first matching local time after takeoff, with a self-check.
7. **Less on one screen:** split into Now / Map / Trip tabs. Removed a duplicate "next flight" card.
8. **Responsive layout:** the postcard scene scales to the screen, type scales with width, wide screens get two columns, touch screens get bigger buttons.
9. **Search instead of a form:** type the flight number; route from the open route database; times optional.
10. **"Seen right now":** PAL flights currently in the air listed first and as tap-to-pick buttons.
11. **Flags instead of city maps:** the paper maps looked blurry when scaled up; flags are vector images and stay sharp. Then flags at their real proportions, stickers moved to the card corners, and the route moved between the cards.
12. **Tab bar fix:** the floating tab bar covered content scrolling under it. It now has its own strip at the bottom. Also told the browser to always fetch the latest version of the page (it was running stale copies after updates).
13. **Route list retry:** if the list can't load (server restarting, offline), it retries on its own instead of giving up.
14. **Published here:** relative paths so one file works both locally and on the site; Cloudflare Pages Functions replace the Python server.
15. **Review and seven fixes:** the "seen right now" list no longer waits ~20 s on a source that never answers; live lookups cut to fit adsb.lol's 500-a-day limit (every 1 to 3 minutes instead of every 30 seconds, answers shared for 30 seconds, one retry); real takeoff and landing times are remembered and reused; renamed to Wife Radar with a link back to the site; distance to destination; share links; installable on a phone; the desktop shortcut now opens the website, so there is one copy instead of two. Also fixed: a flight without times went back to "waiting" a few minutes after landing.
16. **Scheduled times from AeroDataBox:** times fill in by themselves when a flight is added, with "running 40m late" when PAL revises the departure and a note if the flight is cancelled.

---

## Limits

- **One live source:** adsb.lol allows 500 lookups a day per address, and Cloudflare's addresses are shared, so a lookup is sometimes refused; the tracker keeps the last position and tries again. adsb.fi, OpenSky, airplanes.live and adsb.one were all tried as backups and all refuse Cloudflare's servers.
- **Coverage:** live data comes from volunteer receivers. Mid-ocean and parts of the Philippines have gaps; the note estimates there.
- **Callsigns:** assumes flight PR116 broadcasts as `PAL116` (PAL's normal pattern).
- **Time zones:** 60 common PAL airports have exact time zones; the others use a longitude-based estimate (can be an hour off in a few places).
- **Notifications** only fire while the page is open.
- **Route list** is a snapshot (`pal-routes.json`) from November 2026; new PAL flight numbers need a refresh.
- **Learned times** need the page open at takeoff and at landing, and are remembered per browser.
