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)
41 lines
2.3 KiB
Markdown
41 lines
2.3 KiB
Markdown
# 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]`.
|