Inline Comment 0.2.0 - initial public release

Thunderbird/Betterbird add-on (Manifest V3): typing inside a quote splits
the quote and inserts your own text with a marker such as [OH]:.

- English and German user interface
- Licensed under the Mozilla Public License 2.0
- English documentation, JSDoc lint gate, 87 tests (node:test + jsdom)
This commit is contained in:
Oliver_Herb committed 2026-11-24 12:07:09 +01:00
commit 9053327486
57 files changed
+9849

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
# Component: Background Script
**File:** `src/background.js` (loads `lib/settings.js` and `lib/marker.js` first, see `manifest.json`)
**What:** Event page according to Manifest V3. Thunderbird may stop it at any time and start it again
on the next event. Therefore all listeners are registered at the top level, and the on/off state lives
in `storage.session` instead of a variable. If `storage.session` is not available, an in-memory map
is used as a fallback (the state is then lost when the page stops).
**Tasks:**
- Register the compose script (`scripting.compose.registerScripts`) whenever the background script
loads, and inject it into open compose windows after install or update
(`scripting.executeScript`).
- Build and deliver the configuration (`ic:getConfig`), push changes (`ic:config`) after a button
click, an identity change (`compose.onIdentityChanged`) or saved settings (`storage.onChanged`).
- Toolbar button `composeAction`: a click toggles on/off; badge and tooltip show the state.
- Delete the saved on/off state of a closed tab (`tabs.onRemoved`).
- Open the options page after the first install.
**Messages:**
| Type | Direction | Content |
| -------------- | --------------------------- | -------------------------------------------------- |
| `ic:getConfig` | compose script → background | reply: `{active, isPlainText, settings, identity}` |
| `ic:config` | background → compose script | `{config}` as above |
**Button texts:** badge and tooltip are translated through `i18n.getMessage()` (helper `msg()`):
| State | Badge | Tooltip | Badge colour |
| ------ | ------------------------------- | ------------------- | ------------ |
| active | `badgeOn` (en "on", de "an") | `buttonTitleActive` | `#2e7d32` |
| paused | `badgeOff` (en "off", de "aus") | `buttonTitlePaused` | `#757575` |
The default tooltip and the add-on name come from `manifest.json` (`__MSG_actionTitle__`,
`__MSG_extensionName__`). Badge texts should stay at four characters or less. See
[i18n.md](./i18n.md).
**Troubleshooting:** `Tools → Developer Tools → Debug Add-ons → Inline Comment → Inspect` opens the
console of the background script. Messages start with `[Inline Comment]`.
+29
View File
@@ -0,0 +1,29 @@
# Component: Compose Script
**File:** `src/compose/compose.js` (loads `lib/settings.js`, `lib/marker.js` and `lib/quote.js`
first, see `COMPOSE_SCRIPT_FILES`)
**What:** Runs in the editor document of every compose window. Intercepts characters typed inside a
quote, splits the quote and inserts the comment with its marker. Flow:
[system-design.md](../architecture/system-design.md#3-key-press-inside-a-quote).
**Important:**
- `globalThis.__inlineCommentComposeLoaded` prevents the script from running twice (registration
plus injection after install or update).
- Changes to the text go through `document.execCommand`, so they end up in the editor's undo
history. Only the fallback (manual split) changes the DOM directly.
- The HTML comment is built as a DOM node by `createCommentNode()` (`lib/marker.js`) and handed to
the editor as `execCommand("insertHTML", node.outerHTML)`. No HTML is assembled from strings, see
[decision 0005](../decisions/0005-no-markup-sinks.md).
- Markers in the message body:
- quote: `blockquote[type=cite]` (HTML), `[_moz_quote=true]` (plain text)
- own comment: `[data-inline-comment="<id>"]`, marker: `[data-inline-comment-marker]`
- Comments inside a quote (for example inline comments written earlier in the thread) count as part
of the quote and are split like any other quoted text.
- The script shows no user interface texts, so it does not use `_locales`. Date and time in the
marker (`{date}`, `{time}`) are formatted in the application's locale.
**Troubleshooting:** In the settings, under "Advanced", turn on "Diagnostic output in the error
console". The messages appear in the error console of Thunderbird/Betterbird (`Ctrl+Shift+J`) and
start with `[Inline Comment]`.
+97
View File
@@ -0,0 +1,97 @@
# Component: Translations (i18n)
**Files:** `src/_locales/en/messages.json`, `src/_locales/de/messages.json`, `src/lib/i18n.js`;
checked by `test/i18n.test.js`
**What:** The user interface is available in English and German through the standard WebExtension
`i18n` API. `manifest.json` sets `"default_locale": "en"`. Thunderbird picks the messages that match
its user interface language and falls back to English for any other language.
## Message files
Each locale has one `messages.json`. Every entry has a key, the text and a description (the
`example` value is shortened here):
```json
{
"profileOwnSettings": {
"message": "$IDENTITY$ – own settings",
"description": "Options page: entry of the identity drop-down list for an identity with its own settings.",
"placeholders": {
"identity": {
"content": "$1",
"example": "Jane Doe <…>"
}
}
}
}
```
- **Keys:** letters, digits, `_` and `@` only; the project uses camelCase.
- **Descriptions** are notes for translators. They are written in English and are identical in every
locale.
- **Placeholders** (`$NAME$`) are defined under `placeholders`; `$1` … `$9` take the substitutions
passed to `getMessage(key, [values])`. All locales define the same placeholders.
## Where messages are used
| Where | How | Example |
| --------------- | ----------------------------------------------------------- | ------------------------------------ |
| `manifest.json` | `__MSG_key__` | `"name": "__MSG_extensionName__"` |
| `background.js` | `msg(key)` → `i18n.getMessage(key)` | badge `badgeOn` / `badgeOff` |
| `options.html` | `data-i18n` and `data-i18n-aria-label` attributes | `<h2 data-i18n="markerHeading">` |
| `options.js` | `msg(key, substitutions)` for texts that change at run time | `msg("profileOwnSettings", [label])` |
The compose script has no texts of its own and does not use the i18n API.
## `localizeDocument()` (`src/lib/i18n.js`)
`localizeDocument(doc, getMessage)` walks the document once when the options page loads:
| Attribute | Effect |
| ---------------------- | ------------------------------------ |
| `data-i18n="key"` | replaces the element's `textContent` |
| `data-i18n-aria-label` | sets the `aria-label` attribute |
| `data-i18n-title` | sets the `title` attribute |
- The English text in the HTML stays as fallback when a message is missing (`getMessage()` returns an
empty string or no string at all).
- Elements with `data-i18n` must contain text only, because their whole content is replaced. Wrap
the text in a `<span data-i18n="…">` when the element also holds other elements (for example a
checkbox label).
- The function returns the number of replaced texts and attributes.
- Translations are always set as text (`textContent`, `setAttribute`, `new Option()`), never as
markup. A translation therefore cannot inject HTML (see
[decision 0005](../decisions/0005-no-markup-sinks.md)).
`options.js` calls it first thing, together with `document.documentElement.lang =
i18n.getUILanguage()`.
## Adding a string
1. Add the key to `src/_locales/en/messages.json` with the English `message` and an English
`description` that says where the text appears (and any limits, such as the length of a badge).
2. Add the same key to `src/_locales/de/messages.json` with the German `message`, the **same**
`description` and the same `placeholders`.
3. Use it:
- in `options.html`: `data-i18n="key"` (or `data-i18n-aria-label`, `data-i18n-title`) with the
English text as fallback content;
- in a script: `msg("key")` with the key as a **literal string**, so the tests can find it;
- in `manifest.json`: `__MSG_key__`.
4. Run `npm test`.
`test/i18n.test.js` checks that
- `en` and `de` exist and have exactly the same keys,
- every message has a text and the English description, and placeholders match across locales,
- every key used in `options.html`, in `msg()`/`getMessage()` calls and in `manifest.json` exists,
- every message is used somewhere (remove unused keys),
- elements with `data-i18n` contain no child elements,
- the options page is fully translated in both languages (rendered in jsdom).
## Adding a language
Create `src/_locales/<code>/messages.json` with all keys of the English file, translated messages and
unchanged descriptions and placeholders. The key, description and placeholder checks run for every
locale folder automatically; add the new code to the list in the test "options page is fully
translated" as well, so the rendered page is checked too.
+61
View File
@@ -0,0 +1,61 @@
# Component: Options Page and Settings
**Files:** `src/options/options.html`, `options.js`, `options.css`; logic in `src/lib/settings.js`,
preview via `src/lib/marker.js`, translations via `src/lib/i18n.js`
**Storage location:** `storage.local["settings"]`:
```json
{
"global": {
"template": "[{initials}]:",
"textColor": "#0056b3",
"...": "..."
},
"identities": { "id3": { "template": "[{initials} / ACME]:", "...": "..." } }
}
```
- Without its own profile, an identity uses `global`; the page then shows the global settings with
the fields disabled. An own profile is a complete copy that is created from `global` when the
checkbox "Own settings for this identity" is ticked; unticking it deletes the profile.
- Every value read passes through `sanitizeSettings()`: unknown keys are dropped, missing or invalid
values are replaced with the defaults.
**Settings:**
| Key | Default | Meaning |
| ------------------------------------------- | --------------- | -------------------------------------------- |
| `enabledByDefault` | `true` | new emails start with the add-on active |
| `template` | `[{initials}]:` | marker template, max. 200 characters |
| `markerColor`, `markerBold`, `markerItalic` | `#003d80`, bold | style of the marker |
| `textColor`, `textBold`, `textItalic` | `#0056b3` | style of the own text |
| `highlight`, `highlightColor` | off, `#fff8c5` | background of the comment |
| `blankLineBefore`, `blankLineAfter` | off | spacing (1em) before/after the comment¹ |
| `splitMode` | `native` | `native` = editor splits, `manual` = add-on |
| `debug` | off | `console.debug` output of the compose script |
¹ Plain-text messages only use `blankLineBefore`, as a line break before the marker. Colours, bold,
italic and highlight apply to HTML messages only.
Placeholders in the template: `{initials}`, `{name}`, `{email}`, `{date}`, `{time}`. The buttons
below the template field insert them at the cursor.
Changes are saved 300 ms after the last edit and reach open compose windows through
`storage.onChanged`.
"Reset to defaults" asks for confirmation: the first click changes the button text, a second click
within four seconds resets the settings shown.
**Identities:** read with `identities.list()`, or from `accounts.list()` if that is not available.
The profile list shows "All identities (default)" first, then each identity, marked when it has its
own settings.
**Preview:** built with DOM APIs only: two `<blockquote type="cite">` elements with sample text and
the comment node from `createCommentNode()` in between. Marker and texts are always plain text. It
uses the selected identity, otherwise the first identity, otherwise a sample identity from the
messages (`previewSampleName`, `previewSampleEmail`).
**Localization:** static texts carry `data-i18n` attributes and are replaced by `localizeDocument()`
when the page loads; `<html lang>` is set from `i18n.getUILanguage()`. Dynamic texts (profile list,
hints, status, reset confirmation, preview) come from `i18n.getMessage()`. Details:
[i18n.md](./i18n.md).