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

+102
View File
@@ -0,0 +1,102 @@
# Architecture – Overview
## Building blocks
```text
Thunderbird / Betterbird
├── Background script (src/background.js) event page, Manifest V3
│ ├── registers the compose script (scripting.compose)
│ ├── keeps the on/off state per compose window (storage.session, else in memory)
│ ├── "Inline Comment" toolbar button (composeAction, badge "on"/"off")
│ └── delivers the configuration: settings + identity + on/off + plain text?
│
├── Compose script (src/compose/compose.js) in the editor document of every compose window
│ ├── intercepts typed characters inside a quote (keydown, fallback: beforeinput)
│ ├── splits the quote (editor command insertParagraph, fallback: manual split)
│ └── inserts the comment with its marker (insertHTML or insertText)
│
├── Options page (src/options/) settings in storage.local, localized texts
│
├── Translations (src/_locales/{en,de}/messages.json) default locale: en
│
└── Shared library (src/lib/) classic UMD scripts, testable under Node
├── settings.js defaults, validation, profiles per identity, compose script file list
├── marker.js placeholders, initials, comment as DOM node or plain text
├── quote.js quote and gap detection, manual split, caret placement
└── i18n.js localizeDocument() for data-i18n attributes (options page)
```
The library files attach their functions to `globalThis.InlineComment` and also export them through
`module.exports`, so the same file runs in the add-on and in the Node tests. They are classic scripts
rather than ES modules because compose scripts cannot load modules.
## What runs where
| Context | Scripts, in load order | Defined in |
| -------------- | ------------------------------------------------------------------------ | ------------------------------------------- |
| Background | `lib/settings.js`, `lib/marker.js`, `background.js` | `manifest.json` → `background` |
| Compose window | `lib/settings.js`, `lib/marker.js`, `lib/quote.js`, `compose/compose.js` | `COMPOSE_SCRIPT_FILES` in `lib/settings.js` |
| Options page | `lib/settings.js`, `lib/marker.js`, `lib/i18n.js`, `options/options.js` | `<script>` tags in `options.html` |
## Data flow
```text
Options page ──storage.local──▶ Background ──configuration──▶ Compose script
▲ │ │
Button (on/off) ───────────┘ └── tabs.sendMessage on ───────┘
change (settings,
identity, button)
```
The compose script asks for its configuration when it loads and whenever its window gets the focus
(`runtime.sendMessage({type: "ic:getConfig"})`) and keeps it locally, because the decision
"intercept or not" has to be made immediately on every key press.
## User interface texts
All texts the user sees come from `src/_locales/<locale>/messages.json` (English and German, default
`en`):
- `manifest.json`: name, description and button title as `__MSG_key__`.
- Background script: badge text and button tooltip via `i18n.getMessage()`.
- Options page: static texts via `data-i18n` attributes and `localizeDocument()`, dynamic texts
via `i18n.getMessage()`.
The compose script shows no texts of its own; the marker comes from the user's template. Details:
[../components/i18n.md](../components/i18n.md).
## DOM and markup
No file writes markup into a DOM sink (`innerHTML`, `outerHTML =`, `insertAdjacentHTML`,
`document.write`). Elements are built with `createElement`, `textContent` and `setAttribute`. The
editor still receives the HTML comment through `execCommand("insertHTML")`, with the HTML serialized
from such a DOM node. See [decision 0005](../decisions/0005-no-markup-sinks.md).
## Permissions
| Permission | Used for |
| -------------- | ----------------------------------------------------------------------- |
| `compose` | read compose windows (identity, plain text), run the compose script |
| `scripting` | register the compose script and inject it into open windows |
| `storage` | settings (`local`), on/off state per window (`session`) |
| `accountsRead` | name and address of the sender identity for the marker and for profiles |
## Packaging
`npm run build` checks formatting and runs the tests, then `scripts/build.sh` zips the contents of
`src/` into `dist/inline-comment-<version>.xpi` and adds `LICENSE` to the root of the XPI. The
version in `package.json`, `src/manifest.json` and `CHANGELOG.md` must match (checked by
`test/manifest.test.js`).
## Further reading
- Flows in detail: [system-design.md](./system-design.md)
- Components: [background](../components/background.md),
[compose script](../components/compose-script.md), [options page](../components/options.md),
[i18n](../components/i18n.md)
- Decisions:
- [0001 – Manifest V3 with scripting.compose](../decisions/0001-manifest-v3.md)
- [0002 – Let the editor split the quote](../decisions/0002-split-quote-via-editor.md)
- [0003 – keydown as trigger, beforeinput as fallback](../decisions/0003-keydown-as-trigger.md)
- [0004 – Licence: MPL-2.0](../decisions/0004-licence-mpl-2.0.md)
- [0005 – No markup sinks](../decisions/0005-no-markup-sinks.md)
+107
View File
@@ -0,0 +1,107 @@
# System Design – Flows
## 1. Start-up
1. Thunderbird loads the background script (`lib/settings.js`, `lib/marker.js`, `background.js`).
2. `ensureComposeScript()` registers the compose script with the ID `inline-comment-compose` unless it
is already registered. Files and order are listed in `COMPOSE_SCRIPT_FILES` (`lib/settings.js`).
It runs when the background script loads, on `runtime.onStartup` and on `runtime.onInstalled`.
3. On install or update (`runtime.onInstalled`), `injectIntoOpenComposeTabs()` also loads the script
into compose windows that are already open (registered scripts only apply to new windows). On
first install the options page opens.
## 2. A compose window opens
1. The compose script sends `ic:getConfig`.
2. The background script reads `compose.getComposeDetails(tabId)` (identity, plain text), the
identity (`identities.get`), the settings (`resolveSettings`) and the stored on/off state. Without
a stored state, `enabledByDefault` of the identity's settings applies.
3. Reply: `{ active, isPlainText, settings, identity: {name, email} }`. The button badge shows the
state (see [section 4](#4-onoff-and-changes)).
## 3. Key press inside a quote
```text
keydown while active (printable character, no Ctrl/Alt/Cmd shortcut, AltGr allowed)
└─ caret inside a mail quote (blockquote type=cite / _moz_quote)? or (HTML only) in the gap between two quote parts?
no → do nothing, the editor types as usual
yes → preventDefault + stopPropagation, startComment(character)
├─ selection not empty → execCommand("delete")
├─ inside a quote:
│ splitMode "native": execCommand("insertParagraph")
│ caret now outside every quote? → insertComment
│ otherwise → execCommand("undo") + manual split
│ splitMode "manual": manual split (splitCiteAtRange)
├─ in the gap: insertComment
└─ neither (e.g. the deletion removed the quote) → execCommand("insertText")
insertComment
├─ HTML: node = createCommentNode(document, marker, "a", settings, ID) (DOM APIs only)
│ <div data-inline-comment=ID style=…>
│ <span data-inline-comment-marker style=…>[OH]:</span>&nbsp;a
│ </div>
│ execCommand("insertHTML", node.outerHTML)
│ then move the caret to the end of the comment (found by its ID)
└─ plain text: execCommand("insertText", "[OH]: a")
```
- The marker text is the template rendered with `renderTemplate()` and `markerVariables()` (name,
initials and email of the sender identity, current date and time). It is set via `textContent`,
so a template such as `<b>{initials}</b>` stays literal text.
- In `createCommentNode()` the space after the marker and the spaces in the typed text become
non-breaking spaces, so the editor keeps leading and repeated spaces.
- The comment ID has the form `ic-<time>-<random>` and is only used to find the inserted element.
- The styles are inline CSS only (`commentStyle()`, `markerStyle()`), because other mail clients often
strip `<style>` blocks and classes.
Typing further inside the comment is not intercepted: the caret is neither inside a quote nor in the
gap. Enter inside the comment is left to the editor; the new line is not a gap either, because its
nearest non-blank neighbour above is the comment, not a quote, so it gets no new marker.
**Fallback `beforeinput`:** input without a matching key press (on-screen keyboard, emoji picker)
only arrives as `beforeinput` with `inputType = "insertText"`. It is intercepted and inserted in the
next task (`setTimeout 0`), because the editor should not receive further commands while an edit
action is running. Characters that arrive in the meantime are collected in `pendingText`.
## 4. On/off and changes
- Click on the button: invert the state, store it in `storage.session` (`active:<tabId>`; an
in-memory map if `storage.session` is not available), send the configuration to the window
(`tabs.sendMessage`) and update the button.
- Button state:
| State | Badge text (message key) | Badge colour | Tooltip (message key) |
| ------ | ------------------------ | ------------ | --------------------- |
| active | `badgeOn` ("on"/"an") | `#2e7d32` | `buttonTitleActive` |
| paused | `badgeOff` ("off"/"aus") | `#757575` | `buttonTitlePaused` |
- Sender identity changed (`compose.onIdentityChanged`): send the configuration again (marker,
profile).
- Settings saved (`storage.onChanged`, area `local`): send the configuration to all compose windows.
- Window closed (`tabs.onRemoved`): delete its state.
## 5. Manual split (fallback)
`splitCiteAtRange()` cuts the content from the caret to the end of the outermost quote
(`Range.extractContents()`). Partially selected ancestors, including inner quotes, come along as
shallow copies. The rest is put into a shallow copy of the outermost quote and inserted after the
comment. Empty halves are removed. For plain-text quotes, the second half gets a `> ` prefix when
its first line no longer starts with `>`.
The comment node comes from `createCommentNode()` (HTML) or `createPlainCommentElement()` (plain
text: `<span data-inline-comment>` with line breaks around the text) and is inserted with
`insertBefore()`. This change bypasses the editor and is not part of its undo history.
## 6. Logging
All console output starts with `[Inline Comment]`. Warnings and errors are always logged; the compose
script's diagnostic output (`console.debug`) only appears when the `debug` setting is on. The
background script logs a configuration push that could not be delivered (for example to a tab that
was just closed) with `console.debug`, independent of that setting.
## Limitations
- Pasting from the clipboard (`insertFromPaste`) is not handled.
- IME input (`compositionstart`) is not handled.
- Plain text: no gap detection, no blank line after the comment.
- Whether `insertParagraph` via `execCommand` splits the quote like the Enter key can only be
verified in the real editor (manual test). Otherwise the manual split takes over automatically.
+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).
+26
View File
@@ -0,0 +1,26 @@
# 0001 – Manifest V3 with scripting.compose
**Date:** 2026-11-24 · **Status:** accepted
## Context
Thunderbird supports MailExtensions with Manifest V2 and V3. Thunderbird 128 is the first ESR release
with full Manifest V3 support; in Manifest V3, compose scripts are registered through
`scripting.compose`. The add-on is developed and tested with Betterbird 153, which is considerably
newer.
## Decision
Manifest V3 with a minimum version of 128 (`strict_min_version`). Compose scripts are registered with
`scripting.compose.registerScripts` (replaces `composeScripts` from V2), and the background script is
an event page.
## Consequences
- The background script can be stopped at any time: state lives in `storage.session` (an in-memory
map only as a fallback when `storage.session` is missing), listeners are registered at the top
level.
- Registered scripts only apply to new compose windows; windows that are already open get the
script through `scripting.executeScript` after install or update.
- No execution of JavaScript strings, only files.
- Thunderbird versions before 128 are not supported.
@@ -0,0 +1,27 @@
# 0002 – Let the editor split the quote, manual split only as fallback
**Date:** 2026-11-24 · **Status:** accepted, to be confirmed by the manual test
## Context
The original concept was to split the `<blockquote>` directly in the DOM. Direct DOM changes bypass
the editor: Ctrl+Z then does not work reliably, and nested quotes have to be handled by hand. The
Thunderbird mail editor, however, already splits quotes itself when Enter is pressed inside a quote,
right up to the outermost quote.
## Decision
Default (`splitMode = "native"`): trigger `execCommand("insertParagraph")`, which is the same action
as Enter. If the caret is outside every quote afterwards, the comment is inserted with `insertHTML`
(HTML messages) or `insertText` (plain-text messages). Both steps end up in the undo history.
If the editor does not split the quote, `insertParagraph` is reverted with `undo` and the manual
split (`splitCiteAtRange`) is used instead. The manual split can also be selected permanently in the
settings ("Advanced" → "Split the quote" → "by the add-on").
## Consequences
- Ctrl+Z may need two steps (comment, then split).
- Whether `insertParagraph` via `execCommand` splits the quote exactly like the Enter key can only be
verified in the real editor. The automatic fallback keeps the add-on working if it does not.
- The manual split is not part of the editor's undo history.
@@ -0,0 +1,24 @@
# 0003 – keydown as trigger, beforeinput as fallback
**Date:** 2026-11-24 · **Status:** accepted
## Context
The quote should only be split on actual text input, not on clicking or selecting. Candidates are
`keydown` and `beforeinput`. During `beforeinput` an editor action is already running; further
`execCommand` calls inside it are not reliable in Gecko.
## Decision
- `keydown`: printable keys without Ctrl/Alt/Cmd (AltGr allowed, so that `@`, `€`, `{` work).
Intercept, then split and insert immediately.
- `beforeinput` with `inputType = "insertText"`: only for input without a matching key press
(on-screen keyboard, emoji picker). Intercept and insert in the next task; characters arriving in
between are collected in `pendingText`.
## Consequences
- Shortcuts such as Ctrl+C and Ctrl+A, named keys such as the arrow keys, Delete, Backspace and
Enter, and clicks never start a comment; the editor handles them as usual.
- Dead keys (`^`, `´`) deliver the finished character with the second key press; IME input
(`compositionstart`) is not handled.
+59
View File
@@ -0,0 +1,59 @@
# 0004 – Licence: Mozilla Public License 2.0
**Date:** 2026-11-24 · **Status:** accepted
## Context
The repository is published publicly, and the add-on is meant to be listed on addons.thunderbird.net
(ATN). The licence should:
- keep the author's attribution in copies, forks and reused files,
- make sure that improvements to the add-on's own files stay open, without restricting what the
add-on may be combined with,
- be easy to select on ATN and familiar to Thunderbird reviewers and contributors.
## Decision
All source files are licensed under the Mozilla Public License 2.0 (MPL-2.0).
- **Attribution through per-file notices.** Every source file starts with a notice: copyright line,
`SPDX-License-Identifier: MPL-2.0` and the text of MPL Exhibit A. Under §3.4 of the MPL, recipients
may not remove or alter the substance of licence notices, including copyright notices, in the
Source Code Form. Because the notice sits in each file, the attribution travels with every file,
even when single files are copied into another project.
- **File-level copyleft.** Modified versions of covered files must stay under MPL-2.0, and their
source must be available when they are distributed, also as part of an executable form such as an
XPI (§3.1, §3.2). New files in a larger work may use any licence (§3.3), so the add-on can be
combined with code under other licences.
- **Built-in licence on ATN.** MPL-2.0 is one of the licences offered by the ATN listing form, so no
custom licence text has to be maintained there.
- **Common for Thunderbird add-ons.** Thunderbird itself is licensed under MPL-2.0, and many add-ons
use it; reviewers and contributors know its terms.
- In addition, MPL-2.0 contains an explicit patent licence from contributors (§2.1) and, without
Exhibit B in the headers, stays compatible with the GPL and LGPL as "Secondary Licenses" (§3.3).
## Alternatives considered
- **MIT:** short, very permissive and widely known. But there is no copyleft, so modified versions may
be distributed without source, and the attribution lives in a single licence text that is easily
lost when individual files are copied.
- **Apache-2.0:** permissive, with an explicit patent licence and a NOTICE file for attribution. But
there is no copyleft either, and the NOTICE and change-notice handling adds process without keeping
changes to the add-on's own files open.
- **CPAL-1.0:** strong attribution, since the attribution notice has to be shown in the user
interface. But it is rarely used and less familiar to reviewers, it is not a built-in choice on
ATN, it is incompatible with the GPL, and the user interface attribution clause is awkward for an
add-on that lives in the compose window.
## Consequences
- `LICENSE` with the full MPL-2.0 text lies in the repository root and in the root of every XPI
(`scripts/build.sh`).
- Every `.js` and `.css` file starts with the licence header as a block comment (after a shebang, if
any); HTML and SVG files carry it as `<!-- … -->` (HTML directly after `<!doctype html>`), shell
scripts as `# ` lines. JSON files have no header, because JSON has no comments.
- `package.json` declares `"license": "MPL-2.0"`.
- `test/license.test.js` checks the licence text, the header in every source, test and script file,
the package metadata and that `scripts/build.sh` adds `LICENSE` to the XPI.
- New files get the same header. Third-party code may only be added if its licence is compatible, and
it keeps its own notices.
+53
View File
@@ -0,0 +1,53 @@
# 0005 – No markup sinks: build DOM with DOM APIs
**Date:** 2026-11-24 · **Status:** accepted
## Context
Version 0.1.0 assembled the comment block as an HTML string with hand-written escaping and wrote it
into the DOM with `innerHTML` for the manual split and the options page preview. Reviewers on
addons.thunderbird.net (ATN) reject add-ons that create DOM nodes from HTML strings that may contain
unsanitized data, i.e. code that writes markup into DOM sinks: assignments to `innerHTML` or
`outerHTML`, `insertAdjacentHTML` and `document.write`. Such sinks are also the usual way for
untrusted text to turn into markup; here the marker template, the identity name and translated
messages all end up in the page.
At the same time, the comment must reach the mail editor through `execCommand("insertHTML")`: only
editor commands end up in the undo history, so Ctrl+Z keeps working (see
[decision 0002](./0002-split-quote-via-editor.md)).
## Decision
- **DOM APIs only.** Elements are built with `createElement`, `createTextNode`, `textContent`,
`setAttribute`, `append`, `replaceChildren` and `new Option()`. User data and messages are always
set as text, never parsed as markup.
- **Comment block:** `createCommentNode()` in `src/lib/marker.js` builds the `<div>` with the marker
`<span>` and the first text as a DOM node. The options page preview and the manual split insert
this node directly.
- **`insertHTML` stays for undo.** In the editor, the compose script serializes the same node with
`outerHTML` (reading only) and passes the string to `execCommand("insertHTML", …)`. The HTML is
therefore generated from DOM nodes, never assembled by hand, and text such as `<b>` in a marker
template arrives as escaped text.
- **Translations** are applied with `textContent` and `setAttribute` (`localizeDocument()`). Because
`textContent` replaces the whole content, elements with `data-i18n` must contain text only.
- **Guarded by a test:** `test/dom-sinks.test.js` scans every file in `src/` and fails on
`innerHTML`, `outerHTML` assignments, `insertAdjacentHTML` and `document.write`. Reading
`outerHTML` is allowed.
## Alternatives considered
- **Insert the node with DOM methods (such as `insertBefore()`) in the editor as well:** no markup
string at all, but the change bypasses the editor and Ctrl+Z no longer undoes it. Kept only for
the manual split.
- **`execCommand("insertText")` plus formatting commands:** no undo problem, but colours, bold and
data attributes would need several commands and are hard to control. Used only for plain-text
messages.
- **Keep escaping HTML strings by hand (as in 0.1.0) or sanitize them:** still writes into a markup
sink and would not pass the review rule; every new string is another chance to forget the escaping.
## Consequences
- New UI code must use DOM APIs; `npm test` fails otherwise.
- Elements with `data-i18n` must not contain child elements (checked by `test/i18n.test.js`).
- The preview in the options page and the comment in the editor are built by the same function and
look the same.
+142
View File
@@ -0,0 +1,142 @@
# Guide: Develop and test the add-on
This guide covers everything from a fresh clone to a release: build, load the add-on into
Thunderbird, debug it and check the package the way addons.thunderbird.net (ATN) does.
## Prerequisites
- **Node.js 22 or later** with npm (see `engines` in `package.json`).
- **zip** (Info-ZIP) and **bash**, used by `scripts/build.sh` to pack the `.xpi`. On Windows, use
Git Bash or WSL and make sure `zip` is on the `PATH`.
- **Thunderbird 128 or later** (or Betterbird) for loading and testing the add-on.
- Any editor. Formatting is done by Prettier (`npm run format`), so no editor settings are needed.
## Get the code
```bash
git clone https://git.hassio-muc.de/Oliver_Herb/inline-comment.git
cd inline-comment
npm install
```
`npm install` only installs development tools (Prettier, ESLint, jsdom). The add-on itself has no
runtime dependencies.
## Everyday commands
```bash
npm test # unit and DOM tests (node:test + jsdom), no Thunderbird needed
npm run lint # ESLint: JavaScript checks and JSDoc rules
npm run format # format all files with Prettier
npm run check # format check + lint + tests, run before every push
npm run build # check + dist/inline-comment-<version>.xpi
```
Run a single test file with `node --test test/marker.test.js`.
The lint configuration is in `eslint.config.mjs`: the recommended rule sets of ESLint and
`eslint-plugin-jsdoc`, reported as errors, plus a JSDoc block with typed `@param` and `@returns`
tags for every named function. Inline callbacks are exempt. Each part of the code gets the globals
of the environment it runs in (Thunderbird extension scripts, the shared `src/lib/` scripts or
Node).
The `.xpi` is a plain ZIP of `src/` plus the `LICENSE` file. There is no bundler, no transpiler and
no minification: every file from `src/` goes into the package unchanged.
## Repository layout
| Path | Content |
| ------------------- | -------------------------------------------------------------------------- |
| `src/manifest.json` | Manifest V3, permissions, version |
| `src/background.js` | Registers the compose script, toolbar button, configuration per window |
| `src/compose/` | Compose script: catches typing inside a quote and inserts the comment |
| `src/lib/` | Testable logic (settings, marker, quote handling, i18n) as classic scripts |
| `src/options/` | Options page |
| `src/_locales/` | English and German UI texts |
| `test/` | Automated tests |
| `scripts/build.sh` | Packs the `.xpi` |
| `listing/` | Texts for the addons.thunderbird.net listing |
| `.docs/`, `.plan/` | Architecture, decisions, guides, roadmap |
Background: [architecture overview](../architecture/overview.md).
## Load the add-on in Thunderbird
**Temporarily** (until Thunderbird is restarted):
1. Open `about:debugging` (menu `Tools > Developer Tools > Debug Add-ons`, or the gear menu in the
Add-ons Manager) and select **This Thunderbird**.
2. Click **Load Temporary Add-on…** and select `dist/inline-comment-<version>.xpi`.
Alternatively select `src/manifest.json` to load the sources directly without building.
3. After a new build or a change in `src/`, click **Reload** next to the add-on.
4. Open a new compose window, for example a reply to a message that contains a quote.
**Permanently:** open the Add-ons Manager (`Tools > Add-ons and Themes`), click the gear icon,
choose **Install Add-on From File…** and select the `.xpi`. Thunderbird and Betterbird do not
enforce add-on signatures, so the unsigned build installs this way. A version installed from ATN
with the same add-on ID (`inline-comment@ih-engineering.de`) is replaced.
## Debugging
- **Background script:** in `about:debugging > This Thunderbird`, click **Inspect** next to
Inline Comment. The toolbox shows the console of the background script, the debugger and, under
Storage, the extension storage (key `settings` in `storage.local`).
- **Compose script:** it runs inside the editor of each compose window. Its messages appear in the
Error Console: `Tools > Developer Tools > Error Console` or **Ctrl+Shift+J**.
- **Debug output:** enable **Diagnostic output in the error console** in the options (section
Advanced) for detailed messages from the compose script. They are written with `console.debug`;
if they do not show up, check that the console filter includes debug messages.
- All messages of the add-on start with `[Inline Comment]`, so the console can be filtered by that
text.
## Manual test
The automated tests run in jsdom without a real mail editor. Before a release, work through the
manual test plan in Thunderbird: [testplan.md](./testplan.md).
## Release a new version
1. Make the change with tests and run `npm run check`.
2. Raise the version in `package.json` **and** `src/manifest.json` (Semantic Versioning) and add a
section for it to `CHANGELOG.md`. `test/manifest.test.js` checks that all three match.
3. Update the documentation (`README.md`, `README.de.md`, `.docs/` and, if the behaviour or the
permissions changed, `listing/`) in the same commit.
4. Run `npm run build` and work through the [manual test plan](./testplan.md) with the new `.xpi`.
5. Validate the package as described in the next section.
6. Commit, tag and push:
```bash
git commit -am "Release 0.3.0"
git tag -a v0.3.0 -m "Inline Comment 0.3.0"
git push origin main v0.3.0
```
7. Upload the `.xpi` to ATN as a new version. Use the `CHANGELOG.md` section as release notes. The
listing texts are in [listing/](../../listing/README.md).
## Validate the package for ATN
ATN checks every upload with Mozilla's `addons-linter`, as of November 2026 version 6.15.x (ATN's
server pins `~6.15.0`). Run the same version locally against the built package:
```bash
npx addons-linter@6.15.0 dist/inline-comment-<version>.xpi
```
- ATN accepts the upload when the linter reports **0 errors**. Warnings are shown to the reviewer
but do not block the upload.
- **Expected warnings:** `MANIFEST_PERMISSIONS` for `compose` and `accountsRead`. These are
Thunderbird permissions that the Firefox-oriented linter does not know, so the warnings are false
positives.
- Any other warning should be fixed or explained in the notes to reviewers
([listing/notes-to-reviewers.md](../../listing/notes-to-reviewers.md)).
**Optional:** Thunderbird's own [webext-linter](https://github.com/thunderbird/webext-linter) knows
the Thunderbird APIs and permissions and checks against the ATN review policies:
```bash
git clone https://github.com/thunderbird/webext-linter.git
cd webext-linter
npm install
node verify.js <path-to>/dist/inline-comment-<version>.xpi
```
+55
View File
@@ -0,0 +1,55 @@
# Manual test in Thunderbird
The automated tests run in jsdom without a real mail editor. The cases below check the behaviour in
Thunderbird (and Betterbird). Record the result together with the add-on version, the application
and its version and the date in the daily log (`.plan/daily/<date>.md`) or in the release issue.
**Preparation:** load the `.xpi` as a temporary add-on (see [development.md](./development.md)) and
reply to an email with a longer quote, ideally with history, i.e. nested quotes. Compose in HTML
unless a case says otherwise. In the table, `XY` stands for the initials of the sender identity.
## Behaviour
| No. | Step | Expected result |
| --- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| 1 | Click in the middle of a sentence inside the quote, type "a" | Quote split, `[XY]: a` in blue in between, caret after "a" |
| 2 | Keep typing, press Enter, keep typing | No new marker, the text stays blue |
| 3 | Ctrl+Z (twice if needed) | Comment gone, quote whole again |
| 4 | Type inside the inner (nested) quote | All quote levels split cleanly, no empty quote remnants |
| 5 | Inside the quote only click, select, Ctrl+C, arrow keys | Quote unchanged |
| 6 | Press Enter inside the quote, then type | The empty line gets the marker |
| 7 | Reply at the very top, above the quote | No marker |
| 8 | AltGr+Q (`@` on a German keyboard layout) inside the quote | Splits, `[XY]: @` |
| 9 | Select text inside the quote and type | Selection replaced, comment at this position |
| 10 | Click the "Inline Comment" toolbar button | Badge "off", typing inside the quote behaves normally; click again → "on" |
| 11 | Switch the sender (identity), type inside the quote | Marker of the new identity |
| 12 | Change the options (template `{name}:`, colour), use the open window | New values without restart |
| 13 | Send the email to a test mailbox at a webmail provider (Gmail, Outlook) | Colours and marker visible there |
| 14 | Reply in plain-text format, type inside the quote | Quote split, `[XY]: a` without `>` in front |
| 15 | Option "Split the quote: by the add-on (fallback)", cases 1 and 4 | Same result (without Ctrl+Z) |
| 16 | Keep the compose window open, reload the add-on, type inside the quote | Works without a new window |
## User interface languages
Switch the Thunderbird UI language under `Settings > General > Language` (install the language
pack or use a localized build if the language is not offered) and restart Thunderbird.
| No. | Step | Expected result |
| --- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 17 | English UI: open `Add-ons and Themes > Inline Comment > Options`, then a compose window | Add-on listed as "Inline Comment" with the English description; options page, headings, buttons and preview in English; tooltip and badge "on"/"off" in English; no message keys such as `__MSG_…__` visible |
| 18 | German UI: same steps as case 17 | Add-on listed as "Inline-Kommentar"; options page in German ("Inline-Kommentar – Einstellungen", "Profil", "Verhalten", …), German preview text, badge "an"/"aus"; no English leftovers, no clipped labels |
## Applications and versions
| No. | Step | Expected result |
| --- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| 19 | Thunderbird 160 (release channel): install the `.xpi`, run cases 1, 3, 4, 10, 12 and 14 | All pass; no errors or warnings for the add-on in `about:debugging` or the console |
| 20 | Thunderbird 153 ESR: install the `.xpi`, run cases 1, 3, 4, 10, 12 and 14 | All pass; no errors or warnings for the add-on in `about:debugging` or the console |
The full list (cases 1 to 18) runs at least once per release in one of these versions. Betterbird is
based on Thunderbird ESR; before a release, repeat the selection of case 20 there as well.
**If something fails:** enable "Diagnostic output in the error console" in the options, copy the
messages starting with `[Inline Comment]` from the Error Console (Ctrl+Shift+J) and record them with
the case number in the daily log, or open an issue at
<https://git.hassio-muc.de/Oliver_Herb/inline-comment/issues>.