From 86a59358497628e797df31b6e9a9314de1545eb2 Mon Sep 17 00:00:00 2001 From: Harry Roberts Date: Thu, 21 Aug 2025 20:30:19 +0100 Subject: [PATCH] Add demo Initial demo simply shows the classes and properties assigned/applied by Obs.js; future demos should probably show examples of implementation (switching videos for images, etc.). --- README.md | 6 +- demo/index.html | 232 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+), 3 deletions(-) create mode 100644 demo/index.html diff --git a/README.md b/README.md index cb29652..0c5249a 100644 --- a/README.md +++ b/README.md @@ -177,9 +177,9 @@ Obs.js also stores the following properties on the `window.obs` object: | `downlinkMax` | number (Mbps) | Max estimated downlink (if exposed) | `navigator.connection.downlinkMax` | Not used for Stances; informational only | | `connectionCapability` | `'strong' \| 'moderate' \| 'weak'` | Transport assessment | Derived from `rttCategory` and `downlinkBucket` | Strong = low RTT **and** high BW; Weak = high RTT **or** low BW | | `conservationPreference` | `'conserve' \| 'neutral'` | Frugality signal | `dataSaver === true` **or** `batteryLow === true` → `conserve` | — | -| `deliveryMode` | `'rich' \| 'cautious' \| 'lite'` | How “heavy” you should go | Derived from capability and conservation | Rich if **strong** and **not** conserving; Lite if **weak** or **conserve**; else Cautious | -| `canShowRichMedia` | boolean | Convenience: `deliveryMode === 'rich'` | Derived from `deliveryMode` | Shorthand for “go big” | -| `shouldAvoidRichMedia` | boolean | Convenience: `deliveryMode === 'lite'` | Derived from `deliveryMode` | Shorthand for “be frugal” | +| `deliveryMode` | `'rich' \| 'cautious' \| 'lite'` | How ‘heavy’ you should go | Derived from capability and conservation | Rich if **strong** and **not** conserving; Lite if **weak** or **conserve**; else Cautious | +| `canShowRichMedia` | boolean | Convenience: `deliveryMode === 'rich'` | Derived from `deliveryMode` | Shorthand for ‘go big’ | +| `shouldAvoidRichMedia` | boolean | Convenience: `deliveryMode === 'lite'` | Derived from `deliveryMode` | Shorthand for ‘be frugal’ | | `batteryLow` | boolean \| null | Battery ≤20% | Battery API | `true` when battery level is ≤20%; `null` if unknown | | `batteryCritical` | boolean \| null | Battery ≤5% | Battery API | `true` when battery level is ≤5%; `true` in addition to `batteryLow` | | `batteryCharging` | boolean \| null | On charge | Battery API | `null` if unknown | diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..897fad4 --- /dev/null +++ b/demo/index.html @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + Obs.js demo + + + + + + + + + + + +

Obs.js demo

+ +

Obs.js uses the Navigator + and Battery APIs to get contextual information about your users’ connection + strength and battery status.

+ +

It is built and maintained by Harry + Roberts under the MIT license.

+ +

This page shows the .has-* classes on + <html> and the current window.obs object. + Toggle Data Saver, plug/unplug power, or change networks to see updates (where + supported).

+ +

html.classList

+ +
+ +

window.obs

+ +

+
+