moderator-toolbox-nxg-for-reddit / framework/module

framework/module

Functions

buildPolicyMap()

buildPolicyMap(modules): Record<string, SharedSettingPolicy>

Defined in: extension/data/framework/module.ts:212

Builds a sharing-policy map from a set of registered modules. The returned record maps fully-qualified storage keys (Toolbox.{ModuleID}.{settingId}) to their sharedPolicy value. Settings without a sharedPolicy are omitted. Pass the result to getAnonymizedSettings() so the anonymizer knows what to include.

Parameters

modules

readonly Module<any>[]

Returns

Record<string, SharedSettingPolicy>


coerceSetting()

coerceSetting(setting, raw): unknown

Defined in: extension/data/framework/module.ts:133

Coerces a raw storage value to the expected type based on the setting definition. Falls back to the setting’s default when coercion is not possible.

Parameters

setting

Pick<SettingDefinition, "type" | "default" | "min" | "max" | "values">

raw

unknown

Returns

unknown


defineSettings()

defineSettings<T>(settings): T

Defined in: extension/data/framework/module.ts:114

Declares a typed settings array. Pass the result to Module and use InferSettings to derive the initializer option type.

Type Parameters

T

T extends readonly SettingDefinition[]

Parameters

settings

T

Returns

T

Classes

Module

Defined in: extension/data/framework/module.ts:226

A user-toggleable Toolbox feature unit; instances are registered and run by the framework.

Type Parameters

TSettings

TSettings extends Record<string, any> = Record<string, any>

Constructors

Constructor

new Module<TSettings>(__namedParameters, initializer?): Module<TSettings>

Defined in: extension/data/framework/module.ts:243

Parameters
__namedParameters

ModuleOptions

initializer?

ModuleInitializer<TSettings>

Returns

Module<TSettings>

Methods

get()

get<K>(id): Promise<TSettings[K]>

Defined in: extension/data/framework/module.ts:286

Gets the value of a setting.

Type Parameters
K

K extends string

Parameters
id

K

Returns

Promise<TSettings[K]>

getEnabled()

getEnabled(): Promise<boolean>

Defined in: extension/data/framework/module.ts:349

Check whether or not the module is enabled.

Returns

Promise<boolean>

init()

init(): Promise<void>

Defined in: extension/data/framework/module.ts:330

“Starts” the module by calling its initializer.

Returns

Promise<void>

onChange()

onChange<K>(id, callback): () => void

Defined in: extension/data/framework/module.ts:385

Subscribes to live changes for a single setting. The callback is invoked with the new coerced value whenever the setting changes. Returns an unsubscribe function - call it (e.g. from your cleanup function) to stop listening.

Change events are dispatched via the 'tb-setting-changed' CustomEvent on window, which is fired by the settings Redux slice whenever extension storage updates.

Type Parameters
K

K extends string

Parameters
id

K

callback

(newValue) => void

Returns

() => void

Example
function init(s) {
  const unsub = self.onChange('compactHide', newVal => { ... })
  return unsub  // or wrap in a broader cleanup
}
set()

set<K>(id, value): Promise<void>

Defined in: extension/data/framework/module.ts:315

Sets the value of a setting.

Type Parameters
K

K extends string

Parameters
id

K

value

TSettings[K]

Returns

Promise<void>

setEnabled()

setEnabled(enable): Promise<void>

Defined in: extension/data/framework/module.ts:361

Enables or disables the module. This does not take effect until Toolbox is reloaded.

Parameters
enable

boolean

Returns

Promise<void>

Throws

when trying to disable a module that cannot be disabled

Properties

alwaysEnabled

alwaysEnabled: boolean

Defined in: extension/data/framework/module.ts:232

cleanup?

optional cleanup?: ModuleCleanup

Defined in: extension/data/framework/module.ts:239

debugMode

debugMode: boolean

Defined in: extension/data/framework/module.ts:235

If true, the module will only show up when debug mode is enabled

docSlug

docSlug: string

Defined in: extension/data/framework/module.ts:230

Slug for this module’s documentation page on the Toolbox-NXG docs site.

enabledByDefault

enabledByDefault: boolean

Defined in: extension/data/framework/module.ts:231

id

id: string

Defined in: extension/data/framework/module.ts:228

initializer?

optional initializer?: ModuleInitializer<TSettings>

Defined in: extension/data/framework/module.ts:238

name

name: string

Defined in: extension/data/framework/module.ts:227

oldReddit

oldReddit: boolean

Defined in: extension/data/framework/module.ts:236

settings

settings: Map<string, StoredSetting>

Defined in: extension/data/framework/module.ts:240

shreddit

shreddit: boolean

Defined in: extension/data/framework/module.ts:237

sort?

optional sort?: object

Defined in: extension/data/framework/module.ts:241

location

location: string

order

order: number

Interfaces

ModuleOptions

Defined in: extension/data/framework/module.ts:180

Constructor options for a Toolbox Module.

Properties

alwaysEnabled?

optional alwaysEnabled?: boolean

Defined in: extension/data/framework/module.ts:195

When true, the module cannot be disabled by the user.

debug?

optional debug?: boolean

Defined in: extension/data/framework/module.ts:197

When true, the module only appears when debug mode is on.

docSlug?

optional docSlug?: string

Defined in: extension/data/framework/module.ts:191

Slug for this module’s documentation page under the Toolbox-NXG docs site (https://toolbox-nxg.github.io/Toolbox-NXG/user-guide/modules/). Defaults to the lowercased id. Set to an empty string for modules that have no documentation page, which suppresses the help link in the settings UI.

enabledByDefault?

optional enabledByDefault?: boolean

Defined in: extension/data/framework/module.ts:193

Whether the module is enabled when the user hasn’t configured it yet.

id?

optional id?: string

Defined in: extension/data/framework/module.ts:184

Unique identifier; defaults to name with whitespace removed.

name

name: string

Defined in: extension/data/framework/module.ts:182

Human-readable name shown in the settings UI.

oldReddit?

optional oldReddit?: boolean

Defined in: extension/data/framework/module.ts:199

When true, the module only runs on old Reddit; the module registry skips it elsewhere.

settings?

optional settings?: readonly SettingDefinition[]

Defined in: extension/data/framework/module.ts:202

shreddit?

optional shreddit?: boolean

Defined in: extension/data/framework/module.ts:201

When true, the module only runs on the Shreddit UI; the module registry skips it elsewhere.


SettingDefinition

Defined in: extension/data/framework/module.ts:47

Defines a single user-configurable setting for a Toolbox module.

Extended by

Properties

advanced?

optional advanced?: boolean

Defined in: extension/data/framework/module.ts:59

When true, only shown when advanced mode is enabled.

class?

optional class?: string

Defined in: extension/data/framework/module.ts:79

CSS class name to apply to the setting element

debug?

optional debug?: boolean

Defined in: extension/data/framework/module.ts:57

When true, only shown in debug mode.

default?

optional default?: any

Defined in: extension/data/framework/module.ts:54

Default value, or a function that returns it.

description?

optional description?: string

Defined in: extension/data/framework/module.ts:51

event?

optional event?: string

Defined in: extension/data/framework/module.ts:81

Event name to dispatch when an action-type setting is triggered

hidden?

optional hidden?: boolean | (() => boolean | Promise<boolean>)

Defined in: extension/data/framework/module.ts:60

id

id: string

Defined in: extension/data/framework/module.ts:48

labels?

optional labels?: string[]

Defined in: extension/data/framework/module.ts:77

Used by type: 'map' to label the key/value columns

max?

optional max?: number | null

Defined in: extension/data/framework/module.ts:62

Maximum value for numeric settings

min?

optional min?: number

Defined in: extension/data/framework/module.ts:83

Minimum value for numeric settings

oldReddit?

optional oldReddit?: boolean

Defined in: extension/data/framework/module.ts:66

When true, this setting only applies on old Reddit.

placeholder?

optional placeholder?: string

Defined in: extension/data/framework/module.ts:85

Placeholder text shown inside empty text inputs

preview?

optional preview?: string

Defined in: extension/data/framework/module.ts:91

Preview text or HTML shown alongside this setting

previewImageUrl?

optional previewImageUrl?: string

Defined in: extension/data/framework/module.ts:89

URL of a preview image shown alongside this setting

sharedPolicy?

optional sharedPolicy?: SharedSettingPolicy

Defined in: extension/data/framework/module.ts:96

Controls how this setting appears in anonymized diagnostic output. Settings without a policy are omitted from that output entirely.

step?

optional step?: number

Defined in: extension/data/framework/module.ts:64

Step size for numeric settings

storageKey?

optional storageKey?: string

Defined in: extension/data/framework/module.ts:55

type

Defined in: extension/data/framework/module.ts:50

Input type for this setting.

valueLabels?

optional valueLabels?: Partial<Record<string, string>>

Defined in: extension/data/framework/module.ts:75

Optional display labels for type: 'selector' options, keyed by the option’s values entry. Lets the shown text differ from the stored value, so a label can be renamed without changing what is persisted (e.g. to stay compatible with Toolbox 6.x settings sync).

valueNotes?

optional valueNotes?: Partial<Record<string, string>>

Defined in: extension/data/framework/module.ts:87

Maps selector option values to explanatory notes shown in the UI

values?

optional values?: readonly string[]

Defined in: extension/data/framework/module.ts:68

Used by type: 'selector'


StoredSetting

Defined in: extension/data/framework/module.ts:171

A setting as held in a module’s settings map: a full SettingDefinition (the constructor spreads the original definition in) with the fields the constructor always fills in narrowed to required.

Extends

Properties

advanced

advanced: boolean

Defined in: extension/data/framework/module.ts:176

When true, only shown when advanced mode is enabled.

Overrides

SettingDefinition.advanced

class?

optional class?: string

Defined in: extension/data/framework/module.ts:79

CSS class name to apply to the setting element

Inherited from

SettingDefinition.class

debug

debug: boolean

Defined in: extension/data/framework/module.ts:175

When true, only shown in debug mode.

Overrides

SettingDefinition.debug

default?

optional default?: any

Defined in: extension/data/framework/module.ts:54

Default value, or a function that returns it.

Inherited from

SettingDefinition.default

description

description: string

Defined in: extension/data/framework/module.ts:173

Overrides

SettingDefinition.description

event?

optional event?: string

Defined in: extension/data/framework/module.ts:81

Event name to dispatch when an action-type setting is triggered

Inherited from

SettingDefinition.event

hidden?

optional hidden?: boolean | (() => boolean | Promise<boolean>)

Defined in: extension/data/framework/module.ts:60

Inherited from

SettingDefinition.hidden

id

id: string

Defined in: extension/data/framework/module.ts:172

Overrides

SettingDefinition.id

labels?

optional labels?: string[]

Defined in: extension/data/framework/module.ts:77

Used by type: 'map' to label the key/value columns

Inherited from

SettingDefinition.labels

max?

optional max?: number | null

Defined in: extension/data/framework/module.ts:62

Maximum value for numeric settings

Inherited from

SettingDefinition.max

min?

optional min?: number

Defined in: extension/data/framework/module.ts:83

Minimum value for numeric settings

Inherited from

SettingDefinition.min

oldReddit?

optional oldReddit?: boolean

Defined in: extension/data/framework/module.ts:66

When true, this setting only applies on old Reddit.

Inherited from

SettingDefinition.oldReddit

placeholder?

optional placeholder?: string

Defined in: extension/data/framework/module.ts:85

Placeholder text shown inside empty text inputs

Inherited from

SettingDefinition.placeholder

preview?

optional preview?: string

Defined in: extension/data/framework/module.ts:91

Preview text or HTML shown alongside this setting

Inherited from

SettingDefinition.preview

previewImageUrl?

optional previewImageUrl?: string

Defined in: extension/data/framework/module.ts:89

URL of a preview image shown alongside this setting

Inherited from

SettingDefinition.previewImageUrl

sharedPolicy?

optional sharedPolicy?: SharedSettingPolicy

Defined in: extension/data/framework/module.ts:96

Controls how this setting appears in anonymized diagnostic output. Settings without a policy are omitted from that output entirely.

Inherited from

SettingDefinition.sharedPolicy

step?

optional step?: number

Defined in: extension/data/framework/module.ts:64

Step size for numeric settings

Inherited from

SettingDefinition.step

storageKey

storageKey: string

Defined in: extension/data/framework/module.ts:174

Overrides

SettingDefinition.storageKey

type

Defined in: extension/data/framework/module.ts:50

Input type for this setting.

Inherited from

SettingDefinition.type

valueLabels?

optional valueLabels?: Partial<Record<string, string>>

Defined in: extension/data/framework/module.ts:75

Optional display labels for type: 'selector' options, keyed by the option’s values entry. Lets the shown text differ from the stored value, so a label can be renamed without changing what is persisted (e.g. to stay compatible with Toolbox 6.x settings sync).

Inherited from

SettingDefinition.valueLabels

valueNotes?

optional valueNotes?: Partial<Record<string, string>>

Defined in: extension/data/framework/module.ts:87

Maps selector option values to explanatory notes shown in the UI

Inherited from

SettingDefinition.valueNotes

values?

optional values?: readonly string[]

Defined in: extension/data/framework/module.ts:68

Used by type: 'selector'

Inherited from

SettingDefinition.values

Type Aliases

InferSettings

InferSettings<T> = { [Setting in T[number] as Setting["id"]]: InferSettingValue<Setting> }

Defined in: extension/data/framework/module.ts:109

Converts a defineSettings return value into a record mapping setting id to value type.

Type Parameters

T

T extends ReadonlyArray<SettingDefinition>


ModuleInitializer

ModuleInitializer<TSettings> = (this, initialValues) => void | ModuleCleanup | Promise<void | ModuleCleanup>

Defined in: extension/data/framework/module.ts:11

The initializer function called when a module is started. Receives all setting values and may return an optional cleanup function.

Type Parameters

TSettings

TSettings extends Record<string, any> = Record<string, any>

Parameters

this

Module<TSettings>

initialValues

TSettings

Returns

void | ModuleCleanup | Promise<void | ModuleCleanup>


SettingType

SettingType = "boolean" | "text" | "textarea" | "number" | "selector" | "list" | "sublist" | "stringlist" | "array" | "map" | "code" | "syntaxTheme" | "subreddit" | "modsub" | "action" | "page" | "JSON" | "color"

Defined in: extension/data/framework/module.ts:17

All valid input types for a Toolbox setting.


SharedSettingPolicy

SharedSettingPolicy = "raw" | "length" | "populated"

Defined in: extension/data/framework/module.ts:44

How this setting is represented in anonymized diagnostic output:

  • 'raw' - value is included as-is (safe, non-identifying settings).

  • 'length' - only the array/string length is included.

  • 'populated' - only a boolean indicating whether the value is set. Settings without a sharedPolicy are omitted from anonymized output entirely.