Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Changelog

All notable changes to **Message Reader** are documented here.
All notable changes to **Streaming Message Reader** are documented here.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

---

## [1.8.0] - 2026-05-19

### Changed
- **Project renamed** from `message-reader` to `streaming-message-reader`. Script file renamed to `streaming-message-reader.user.js`. `@name`, `@namespace`, console prefix (`[Streaming Message Reader]`), and window guard flag (`__streamingMessageReaderLoaded`) updated accordingly.
- GitHub repository renamed to `sbcmsbgithub/streaming-message-reader`.
- `localStorage` key intentionally kept as `message_reader_config_v1` so existing users retain their settings.

---

## [1.7.5] - 2026-05-18

### Changed
Expand Down Expand Up @@ -172,16 +181,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

---

[1.7.5]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.7.5
[1.7.4]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.7.4
[1.7.3]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.7.3
[1.7.2]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.7.2
[1.7.1]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.7.1
[1.7.0]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.7.0
[1.6.0]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.6.0
[1.5.0]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.5.0
[1.4.0]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.4.0
[1.3.0]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.3.0
[1.2.0]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.2.0
[1.1.0]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.1.0
[1.0.0]: https://github.com/sbcmsbgithub/message-reader/releases/tag/v1.0.0
[1.8.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.8.0
[1.7.5]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.7.5
[1.7.4]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.7.4
[1.7.3]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.7.3
[1.7.2]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.7.2
[1.7.1]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.7.1
[1.7.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.7.0
[1.6.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.6.0
[1.5.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.5.0
[1.4.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.4.0
[1.3.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.3.0
[1.2.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.2.0
[1.1.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.1.0
[1.0.0]: https://github.com/sbcmsbgithub/streaming-message-reader/releases/tag/v1.0.0
53 changes: 28 additions & 25 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Project context for [Claude Code](https://docs.claude.com/en/docs/claude-code).

A single-file userscript that reads new chat messages aloud on **any website**. The default container selector targets the Angular-based chat layout used on the primary target site, but the "Pick Message Area" button lets it work on any site. Distributed via Tampermonkey/Violentmonkey. No build step, no package manager, no framework.

The deliverable is **`message-reader.user.js`** — that is the entire product.
The deliverable is **`streaming-message-reader.user.js`** — that is the entire product.

---

Expand Down Expand Up @@ -47,24 +47,25 @@ Each message renders visually as:

Components:
- **Timestamp** in brackets: `[6:05 PM]` (sometimes appears unbracketed as `6:05 PM`).
- **Date stamp**: e.g. `May 18` — injected by the chat UI into the element's `innerText`.
- **Sender** display name: `Alice Smith` (first + last, sometimes single name).
- **Badges**: Short pills like `ADMIN`, `MOD`, `VIP`, `PRO`, `OWNER`, `STAFF`, `TEAM`. Currently treated as noise.
- **Body**: The actual message text.
- **Body**: The actual message text. The chat UI may also prefix the body with `"FirstName: "`.

The DOM order of these elements within `<app-st-compactmessage>` is **not** guaranteed to match the visual order — different rendering paths put the sender in the avatar tooltip AND in the visible label, which is why the extractor strips the sender from the body **repeatedly** (see `extractMessageFromRoot` in the script).

---

## Architecture

The entire script lives inside one IIFE in `message-reader.user.js`. Sections (in order they appear):
The entire script lives inside one IIFE in `streaming-message-reader.user.js`. Sections (in order they appear):

1. **Boot & guards** — `__messageReaderLoaded` to prevent double-injection; `waitForBody` to defer until DOM exists.
1. **Boot & guards** — `__streamingMessageReaderLoaded` to prevent double-injection; `waitForBody` to defer until DOM exists.
2. **Config** — Defaults object, `localStorage` load/save (key: `message_reader_config_v1`).
3. **Speech + playback state machine** — States: `idle` / `playing` / `paused` / `stopped`. Queue array. **Generation counter** (`utteranceGen`) to invalidate stale `onend` callbacks when the user skips or stops.
4. **Extraction** (`extractMessageFromRoot`) — Angular-specific parsing logic. See "Extraction strategy" below.
5. **Container detection** (`autoDetectChatContainer`) — Prefers `app-roomscroller`; falls back to walking up from any `app-st-compactmessage` to find a common ancestor.
6. **Observer + dedupe** — MutationObserver with a 200-entry recent-spoken set keyed by `sender|body`.
6. **Observer + dedupe** — MutationObserver with a 5000-entry recent-spoken set keyed by `sender|body`.
7. **Element picker** — Click-to-select fallback if auto-detection fails. Builds a CSS selector using id/class/nth-of-type.
8. **UI panel** — Vanilla HTML/CSS injected into `document.body`. Two zones:
- **`.playback`** — Always visible: state indicator + Start/Pause/Skip/Stop buttons.
Expand All @@ -78,11 +79,13 @@ The Angular SPA's DOM duplicates the sender name in some renderings (avatar tool
1. **Get sender from DOM** via selector matching `*sender*`, `*author*`, `*username*`, etc.
2. **Capture the first timestamp** seen anywhere in `innerText` (for the optional "announce time" feature).
3. **Aggressive cleanup of the body**:
- Strip ALL timestamps (bracketed and bare) via two regexes — `TS_BRACKET` and `TS_BARE`.
- Repeatedly strip the sender name from the start of the body (handles the duplicate-name case).
- Strip leading badge words (`T3TG`, `ADMIN`, etc.) using the `BADGE_WORDS` Set.
- Strip ALL timestamps (bracketed and bare) via `TS_BRACKET` and `TS_BARE`.
- Strip date stamps (e.g. `May 18`) via `DATE_RE`.
- Strip sender name from the body using `stripSenderFromStart` (full name, then first name).
- Strip leading badge words (`ADMIN`, etc.) using the `BADGE_WORDS` Set.
- Fallback: `"Name: body"` regex if the DOM-based sender extraction failed.
4. **Apply first-name-only** if `config.firstNameOnly` is true — splits sender on whitespace and keeps only the first word.
4. **`normalizeMsg()`** — final cleanup pass applied to all messages before the dedup key is computed: date strip, sender strip (full + first name), leading timestamp strip, and a catch-all `"Name: "` prefix strip.
5. **Apply first-name-only** if `config.firstNameOnly` is true — splits sender on whitespace and keeps only the first word.

Return shape: `{ fullSender, sender, body, timeText }` where:
- `fullSender` — full name (used for ignore-list matching, never changes).
Expand All @@ -92,17 +95,17 @@ Return shape: `{ fullSender, sender, body, timeText }` where:

### Spoken output construction

In `handleRootNode`, the spoken string is assembled from parts:
In `handleNode`, the spoken string is assembled from parts:

```js
const parts = [];
if (config.announceTime && msg.timeText) parts.push(msg.timeText);
if (config.readSender && msg.sender) parts.push(msg.sender + ':');
parts.push(msg.body);
const spoken = parts.join(' ').trim();
const spoken = parts.join(' ').replace(URL_RE, 'URL posted').replace(/\s+/g, ' ').trim();
```

So toggling features just adds/removes parts — no special-case branching.
So toggling features just adds/removes parts — no special-case branching. URLs are always replaced with "URL posted".

### Skip semantics (subtle)

Expand All @@ -115,7 +118,7 @@ So toggling features just adds/removes parts — no special-case branching.
## Code conventions used in this file

- **Single IIFE.** Everything is inside `(function () { 'use strict'; … })()` to keep the global namespace clean.
- **`LOG` / `ERR` helpers** at the top — every notable action logs `[Message Reader] …` to the console for debuggability.
- **`LOG` / `ERR` helpers** at the top — every notable action logs `[Streaming Message Reader] …` to the console for debuggability.
- **Defensive `try/catch`** around anything that touches the DOM, `localStorage`, or `speechSynthesis`. The script must never throw in a way that breaks the host page.
- **Config is the single source of truth.** UI hydrates from config on mount; any UI change writes back to config and `saveConfig()`s immediately.
- **`!important` on panel positioning** — host-page CSS can aggressively override our panel's position; `!important` keeps it pinned.
Expand All @@ -130,13 +133,13 @@ Stored in `localStorage` under key `message_reader_config_v1`. Defaults defined
```js
{
enabled: false, // master switch for queueing new messages
allowedUrls: '', // newline/comma-separated URL patterns; empty = all sites
allowedUrls: 'vtf.t3live.com', // URL patterns; empty = all sites
selector: '', // CSS selector for the chat container (empty = auto-detect)
rate: 1.0, // speech rate (0.5 – 2.0)
pitch: 1.0, // speech pitch (0 – 2)
volume: 1.0, // speech volume (0 – 1)
voiceURI: '', // selected SpeechSynthesisVoice.voiceURI
readSender: true, // prepend sender name to spoken text
readSender: false, // prepend sender name to spoken text
firstNameOnly: true, // "Alice Smith" → "Alice"
announceTime: false, // prepend timestamp to spoken text
skipOwnMessages: true, // filter using `myUsername`
Expand All @@ -152,13 +155,13 @@ When adding new config fields, **always update `defaults`** so existing users ge

## How to make changes

1. Edit `message-reader.user.js`.
1. Edit `streaming-message-reader.user.js`.
2. **Bump the `// @version` field** in the metadata block (semver — patch for bugfix, minor for feature, major for breaking).
3. **Add an entry to `CHANGELOG.md`** with the new version, the date, and a bulleted list of changes.
4. **Test on a live session**:
- Open Tampermonkey dashboard → edit the installed script → paste the new contents → save.
- Hard refresh the target tab (`Ctrl+Shift+R`).
- Open DevTools console; look for `[Message Reader] UI mounted.` and any errors.
- Open DevTools console; look for `[Streaming Message Reader] UI mounted.` and any errors.
- Verify the panel renders correctly.
- Verify a new message gets read aloud as expected.
- Verify Start/Pause/Skip/Stop all work.
Expand All @@ -169,7 +172,7 @@ When adding new config fields, **always update `defaults`** so existing users ge

```js
// Is the script loaded?
window.__messageReaderLoaded
window.__streamingMessageReaderLoaded

// Is the panel mounted?
document.getElementById('msg-reader-panel')
Expand Down Expand Up @@ -209,13 +212,13 @@ These are NOT bugs to "fix" without discussion — they're known tradeoffs:
## Files in this repo

```
message-reader/
├── README.md — user-facing docs
├── CLAUDE.md — this file (project context for Claude Code)
├── CHANGELOG.md — version history
├── LICENSE — MIT
├── .gitignore — standard
└── message-reader.user.js — the entire product
streaming-message-reader/
├── README.md — user-facing docs
├── CLAUDE.md — this file (project context for Claude Code)
├── CHANGELOG.md — version history
├── LICENSE — MIT
├── .gitignore — standard
└── streaming-message-reader.user.js — the entire product
```

---
Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Message Reader
# Streaming Message Reader

A Tampermonkey/Violentmonkey userscript that reads new chat messages aloud on **any website** using the browser's built-in text-to-speech, with a floating control panel for playback (Start / Pause / Skip / Stop) and per-user filtering.

Expand All @@ -11,11 +11,14 @@ The default container selector targets the Angular-based chat layout used on the
- **Works on any website** — use the "Pick Message Area" button to select any element on any page as the message source
- **Live chat narration** — new messages are spoken as they arrive
- **Playback controls** — Start, Pause, Skip current message, Stop (clears the queue)
- **Smart sender formatting** — extracts sender and body from common DOM patterns (`<strong>`, `<b>`, class-name hints, `name: body` fallback)
- **Smart body extraction** — strips timestamps, date stamps, sender prefixes, and badge words injected by the chat UI
- **URL redaction** — URLs in messages are replaced with "URL posted" instead of being read aloud
- **Optional sender name** — toggle whether to prepend the sender's name (off by default)
- **Optional first-name only** — "Alice Smith" → "Alice"
- **Optional timestamp announcement** — toggle whether to read "10:57 AM" out loud
- **Ignore list** — comma-separated usernames to skip (matches full or first name)
- **Skip-own-messages** — don't read messages you yourself sent
- **Allowed sites** — restrict the panel to specific URLs; leave empty to show on all sites
- **Voice / rate / volume picker** — uses any voice installed in your OS
- **Collapsible UI** — playback controls remain visible while settings collapse
- **Draggable panel** — move it out of the way
Expand All @@ -30,9 +33,9 @@ The default container selector targets the Angular-based chat layout used on the
2. Open the Tampermonkey dashboard.
3. Click **+ → Create a new script**.
4. Delete the template code.
5. Paste the contents of [`message-reader.user.js`](./message-reader.user.js).
5. Paste the contents of [`streaming-message-reader.user.js`](./streaming-message-reader.user.js).
6. Save (`Ctrl+S`).
7. Open the target site. The orange-bordered **Message Reader** panel appears in the top-right corner.
7. Open the target site. The orange-bordered **Streaming Message Reader** panel appears in the top-right corner.

---

Expand All @@ -59,12 +62,13 @@ New messages in the watched container will be spoken as they arrive.
| Setting | Default | Description |
|---|---|---|
| Read new messages as they arrive | off | Master toggle for queueing new messages |
| Sender name | off | Prepend the sender's name to every message |
| First name only | on | Read "Alice" instead of "Alice Smith" |
| Announce sender name | on | Prepend the sender to every message |
| Announce timestamp | off | Prepend "10:57 AM" to every message |
| Skip my own messages | on | Combined with "My username" below |
| Timestamp | off | Prepend "10:57 AM" to every message |
| Skip own msgs | on | Combined with "My username" below |
| My username | empty | Your display name, used for the self-skip filter |
| Skip messages from these users | empty | Comma-separated ignore list (matches full or first name) |
| Skip these users | empty | Comma-separated ignore list (matches full or first name) |
| Allowed sites | primary site | URL patterns — one per line; empty = show on all sites |
| Voice / Rate / Volume | system default / 1.0 / 1.0 | Standard text-to-speech parameters |

---
Expand All @@ -74,10 +78,10 @@ New messages in the watched container will be spoken as they arrive.
1. Locates the chat container (uses the configured CSS selector, then auto-detects, then falls back to the element picker).
2. Attaches a `MutationObserver` to that container with `subtree: true`.
3. When new nodes are added, tries Angular-specific extraction (`<app-st-compactmessage>`) first, then falls back to generic extraction.
4. Generic extraction: finds sender in `<strong>`, `<b>`, or elements with common class names; strips timestamps; falls back to `name: body` splitting.
5. De-duplicates against a 200-entry recent-messages buffer.
4. Generic extraction: finds sender in `<strong>`, `<b>`, or elements with common class names; strips timestamps and date stamps; falls back to `name: body` splitting.
5. De-duplicates against a 5000-entry recent-messages buffer.
6. Filters using the ignore list / self-skip.
7. Builds the spoken string: `[time] FirstName: message` (parts individually toggleable).
7. Builds the spoken string from toggleable parts (timestamp, sender, body); replaces URLs with "URL posted".
8. Pushes onto a queue and feeds the browser's `SpeechSynthesis` one utterance at a time.

A generation counter invalidates pending `onend` callbacks when the user hits Skip or Stop, so playback control is always precise.
Expand Down Expand Up @@ -108,11 +112,11 @@ Requires the Web Speech API (`window.speechSynthesis`), available in all modern
Single-file userscript — no build step required.

```bash
git clone https://github.com/sbcmsbgithub/message-reader.git
cd message-reader
git clone https://github.com/sbcmsbgithub/streaming-message-reader.git
cd streaming-message-reader

# Edit
vim message-reader.user.js
vim streaming-message-reader.user.js

# Test: paste the updated source into Tampermonkey's editor and reload the target tab.
```
Expand Down
Loading