moderator-toolbox-nxg-for-reddit / framework/module
framework/module¶
Functions¶
buildPolicyMap()¶
buildPolicyMap(
modules):Record<string,SharedSettingPolicy>
Defined in: extension/data/framework/module.ts:234
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:135
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:116
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:248
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:265
Parameters¶
__namedParameters¶
initializer?¶
ModuleInitializer<TSettings>
Returns¶
Module<TSettings>
Methods¶
get()¶
get<
K>(id,snapshot?):Promise<TSettings[K]>
Defined in: extension/data/framework/module.ts:313
Gets the value of a setting.
Type Parameters¶
K¶
K extends string
Parameters¶
id¶
K
The setting id to read.
snapshot?¶
An optional already-fetched settings object (see getSettings). When provided, the value is read from it instead of a fresh storage round-trip - used by init so a whole init pass reads storage once.
Returns¶
Promise<TSettings[K]>
getEnabled()¶
getEnabled(
snapshot?):Promise<boolean>
Defined in: extension/data/framework/module.ts:380
Check whether or not the module is enabled.
Parameters¶
snapshot?¶
An optional already-fetched settings object; when provided the enabled flag is read from it instead of a fresh storage round-trip.
Returns¶
Promise<boolean>
init()¶
init(
snapshot?):Promise<void>
Defined in: extension/data/framework/module.ts:357
“Starts” the module by calling its initializer.
Parameters¶
snapshot?¶
Returns¶
Promise<void>
onChange()¶
onChange<
K>(id,callback): () =>void
Defined in: extension/data/framework/module.ts:419
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:342
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:395
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:254
cleanup?¶
optionalcleanup?:ModuleCleanup
Defined in: extension/data/framework/module.ts:261
debugMode¶
debugMode:
boolean
Defined in: extension/data/framework/module.ts:257
If true, the module will only show up when debug mode is enabled
docSlug¶
docSlug:
string
Defined in: extension/data/framework/module.ts:252
Slug for this module’s documentation page on the Toolbox-NXG docs site.
enabledByDefault¶
enabledByDefault:
boolean
Defined in: extension/data/framework/module.ts:253
id¶
id:
string
Defined in: extension/data/framework/module.ts:250
initializer?¶
optionalinitializer?:ModuleInitializer<TSettings>
Defined in: extension/data/framework/module.ts:260
name¶
name:
string
Defined in: extension/data/framework/module.ts:249
oldReddit¶
oldReddit:
boolean
Defined in: extension/data/framework/module.ts:258
settings¶
settings:
Map<string,StoredSetting>
Defined in: extension/data/framework/module.ts:262
shreddit¶
shreddit:
boolean
Defined in: extension/data/framework/module.ts:259
sort?¶
optionalsort?:object
Defined in: extension/data/framework/module.ts:263
location¶
location:
string
order¶
order:
number
Interfaces¶
ModuleOptions¶
Defined in: extension/data/framework/module.ts:202
Constructor options for a Toolbox Module.
Properties¶
alwaysEnabled?¶
optionalalwaysEnabled?:boolean
Defined in: extension/data/framework/module.ts:217
When true, the module cannot be disabled by the user.
debug?¶
optionaldebug?:boolean
Defined in: extension/data/framework/module.ts:219
When true, the module only appears when debug mode is on.
docSlug?¶
optionaldocSlug?:string
Defined in: extension/data/framework/module.ts:213
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?¶
optionalenabledByDefault?:boolean
Defined in: extension/data/framework/module.ts:215
Whether the module is enabled when the user hasn’t configured it yet.
id?¶
optionalid?:string
Defined in: extension/data/framework/module.ts:206
Unique identifier; defaults to name with whitespace removed.
name¶
name:
string
Defined in: extension/data/framework/module.ts:204
Human-readable name shown in the settings UI.
oldReddit?¶
optionaloldReddit?:boolean
Defined in: extension/data/framework/module.ts:221
When true, the module only runs on old Reddit; the module registry skips it elsewhere.
settings?¶
optionalsettings?: readonlySettingDefinition[]
Defined in: extension/data/framework/module.ts:224
shreddit?¶
optionalshreddit?:boolean
Defined in: extension/data/framework/module.ts:223
When true, the module only runs on the Shreddit UI; the module registry skips it elsewhere.
SettingDefinition¶
Defined in: extension/data/framework/module.ts:49
Defines a single user-configurable setting for a Toolbox module.
Extended by¶
Properties¶
advanced?¶
optionaladvanced?:boolean
Defined in: extension/data/framework/module.ts:61
When true, only shown when advanced mode is enabled.
class?¶
optionalclass?:string
Defined in: extension/data/framework/module.ts:81
CSS class name to apply to the setting element
debug?¶
optionaldebug?:boolean
Defined in: extension/data/framework/module.ts:59
When true, only shown in debug mode.
default?¶
optionaldefault?:any
Defined in: extension/data/framework/module.ts:56
Default value, or a function that returns it.
description?¶
optionaldescription?:string
Defined in: extension/data/framework/module.ts:53
event?¶
optionalevent?:string
Defined in: extension/data/framework/module.ts:83
Event name to dispatch when an action-type setting is triggered
id¶
id:
string
Defined in: extension/data/framework/module.ts:50
labels?¶
optionallabels?:string[]
Defined in: extension/data/framework/module.ts:79
Used by type: 'map' to label the key/value columns
max?¶
optionalmax?:number|null
Defined in: extension/data/framework/module.ts:64
Maximum value for numeric settings
min?¶
optionalmin?:number
Defined in: extension/data/framework/module.ts:85
Minimum value for numeric settings
oldReddit?¶
optionaloldReddit?:boolean
Defined in: extension/data/framework/module.ts:68
When true, this setting only applies on old Reddit.
placeholder?¶
optionalplaceholder?:string
Defined in: extension/data/framework/module.ts:87
Placeholder text shown inside empty text inputs
preview?¶
optionalpreview?:string
Defined in: extension/data/framework/module.ts:93
Preview text or HTML shown alongside this setting
previewImageUrl?¶
optionalpreviewImageUrl?:string
Defined in: extension/data/framework/module.ts:91
URL of a preview image shown alongside this setting
step?¶
optionalstep?:number
Defined in: extension/data/framework/module.ts:66
Step size for numeric settings
storageKey?¶
optionalstorageKey?:string
Defined in: extension/data/framework/module.ts:57
type¶
type:
SettingType
Defined in: extension/data/framework/module.ts:52
Input type for this setting.
valueLabels?¶
optionalvalueLabels?:Partial<Record<string,string>>
Defined in: extension/data/framework/module.ts:77
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?¶
optionalvalueNotes?:Partial<Record<string,string>>
Defined in: extension/data/framework/module.ts:89
Maps selector option values to explanatory notes shown in the UI
values?¶
optionalvalues?: readonlystring[]
Defined in: extension/data/framework/module.ts:70
Used by type: 'selector'
StoredSetting¶
Defined in: extension/data/framework/module.ts:193
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:198
When true, only shown when advanced mode is enabled.
Overrides¶
class?¶
optionalclass?:string
Defined in: extension/data/framework/module.ts:81
CSS class name to apply to the setting element
Inherited from¶
debug¶
debug:
boolean
Defined in: extension/data/framework/module.ts:197
When true, only shown in debug mode.
Overrides¶
default?¶
optionaldefault?:any
Defined in: extension/data/framework/module.ts:56
Default value, or a function that returns it.
Inherited from¶
description¶
description:
string
Defined in: extension/data/framework/module.ts:195
Overrides¶
event?¶
optionalevent?:string
Defined in: extension/data/framework/module.ts:83
Event name to dispatch when an action-type setting is triggered
Inherited from¶
hidden?¶
optionalhidden?:boolean| (() =>boolean|Promise<boolean>)
Defined in: extension/data/framework/module.ts:62
Inherited from¶
id¶
id:
string
Defined in: extension/data/framework/module.ts:194
Overrides¶
labels?¶
optionallabels?:string[]
Defined in: extension/data/framework/module.ts:79
Used by type: 'map' to label the key/value columns
Inherited from¶
max?¶
optionalmax?:number|null
Defined in: extension/data/framework/module.ts:64
Maximum value for numeric settings
Inherited from¶
min?¶
optionalmin?:number
Defined in: extension/data/framework/module.ts:85
Minimum value for numeric settings
Inherited from¶
oldReddit?¶
optionaloldReddit?:boolean
Defined in: extension/data/framework/module.ts:68
When true, this setting only applies on old Reddit.
Inherited from¶
placeholder?¶
optionalplaceholder?:string
Defined in: extension/data/framework/module.ts:87
Placeholder text shown inside empty text inputs
Inherited from¶
preview?¶
optionalpreview?:string
Defined in: extension/data/framework/module.ts:93
Preview text or HTML shown alongside this setting
Inherited from¶
previewImageUrl?¶
optionalpreviewImageUrl?:string
Defined in: extension/data/framework/module.ts:91
URL of a preview image shown alongside this setting
Inherited from¶
sharedPolicy?¶
optionalsharedPolicy?:SharedSettingPolicy
Defined in: extension/data/framework/module.ts:98
Controls how this setting appears in anonymized diagnostic output. Settings without a policy are omitted from that output entirely.
Inherited from¶
step?¶
optionalstep?:number
Defined in: extension/data/framework/module.ts:66
Step size for numeric settings
Inherited from¶
storageKey¶
storageKey:
string
Defined in: extension/data/framework/module.ts:196
Overrides¶
type¶
type:
SettingType
Defined in: extension/data/framework/module.ts:52
Input type for this setting.
Inherited from¶
valueLabels?¶
optionalvalueLabels?:Partial<Record<string,string>>
Defined in: extension/data/framework/module.ts:77
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¶
valueNotes?¶
optionalvalueNotes?:Partial<Record<string,string>>
Defined in: extension/data/framework/module.ts:89
Maps selector option values to explanatory notes shown in the UI
Inherited from¶
values?¶
optionalvalues?: readonlystring[]
Defined in: extension/data/framework/module.ts:70
Used by type: 'selector'
Inherited from¶
Type Aliases¶
InferSettings¶
InferSettings<
T> ={ [Setting in T[number] as Setting["id"]]: InferSettingValue<Setting> }
Defined in: extension/data/framework/module.ts:111
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:13
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:19
All valid input types for a Toolbox setting.