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¶
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?¶
optionalcleanup?: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?¶
optionalinitializer?: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?¶
optionalsort?: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?¶
optionalalwaysEnabled?:boolean
Defined in: extension/data/framework/module.ts:195
When true, the module cannot be disabled by the user.
debug?¶
optionaldebug?:boolean
Defined in: extension/data/framework/module.ts:197
When true, the module only appears when debug mode is on.
docSlug?¶
optionaldocSlug?: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?¶
optionalenabledByDefault?:boolean
Defined in: extension/data/framework/module.ts:193
Whether the module is enabled when the user hasn’t configured it yet.
id?¶
optionalid?: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?¶
optionaloldReddit?: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?¶
optionalsettings?: readonlySettingDefinition[]
Defined in: extension/data/framework/module.ts:202
shreddit?¶
optionalshreddit?: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?¶
optionaladvanced?:boolean
Defined in: extension/data/framework/module.ts:59
When true, only shown when advanced mode is enabled.
class?¶
optionalclass?:string
Defined in: extension/data/framework/module.ts:79
CSS class name to apply to the setting element
debug?¶
optionaldebug?:boolean
Defined in: extension/data/framework/module.ts:57
When true, only shown in debug mode.
default?¶
optionaldefault?:any
Defined in: extension/data/framework/module.ts:54
Default value, or a function that returns it.
description?¶
optionaldescription?:string
Defined in: extension/data/framework/module.ts:51
event?¶
optionalevent?:string
Defined in: extension/data/framework/module.ts:81
Event name to dispatch when an action-type setting is triggered
id¶
id:
string
Defined in: extension/data/framework/module.ts:48
labels?¶
optionallabels?:string[]
Defined in: extension/data/framework/module.ts:77
Used by type: 'map' to label the key/value columns
max?¶
optionalmax?:number|null
Defined in: extension/data/framework/module.ts:62
Maximum value for numeric settings
min?¶
optionalmin?:number
Defined in: extension/data/framework/module.ts:83
Minimum value for numeric settings
oldReddit?¶
optionaloldReddit?:boolean
Defined in: extension/data/framework/module.ts:66
When true, this setting only applies on old Reddit.
placeholder?¶
optionalplaceholder?:string
Defined in: extension/data/framework/module.ts:85
Placeholder text shown inside empty text inputs
preview?¶
optionalpreview?:string
Defined in: extension/data/framework/module.ts:91
Preview text or HTML shown alongside this setting
previewImageUrl?¶
optionalpreviewImageUrl?:string
Defined in: extension/data/framework/module.ts:89
URL of a preview image shown alongside this setting
step?¶
optionalstep?:number
Defined in: extension/data/framework/module.ts:64
Step size for numeric settings
storageKey?¶
optionalstorageKey?:string
Defined in: extension/data/framework/module.ts:55
type¶
type:
SettingType
Defined in: extension/data/framework/module.ts:50
Input type for this setting.
valueLabels?¶
optionalvalueLabels?: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?¶
optionalvalueNotes?:Partial<Record<string,string>>
Defined in: extension/data/framework/module.ts:87
Maps selector option values to explanatory notes shown in the UI
values?¶
optionalvalues?: readonlystring[]
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¶
class?¶
optionalclass?:string
Defined in: extension/data/framework/module.ts:79
CSS class name to apply to the setting element
Inherited from¶
debug¶
debug:
boolean
Defined in: extension/data/framework/module.ts:175
When true, only shown in debug mode.
Overrides¶
default?¶
optionaldefault?:any
Defined in: extension/data/framework/module.ts:54
Default value, or a function that returns it.
Inherited from¶
description¶
description:
string
Defined in: extension/data/framework/module.ts:173
Overrides¶
event?¶
optionalevent?:string
Defined in: extension/data/framework/module.ts:81
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:60
Inherited from¶
id¶
id:
string
Defined in: extension/data/framework/module.ts:172
Overrides¶
labels?¶
optionallabels?:string[]
Defined in: extension/data/framework/module.ts:77
Used by type: 'map' to label the key/value columns
Inherited from¶
max?¶
optionalmax?:number|null
Defined in: extension/data/framework/module.ts:62
Maximum value for numeric settings
Inherited from¶
min?¶
optionalmin?:number
Defined in: extension/data/framework/module.ts:83
Minimum value for numeric settings
Inherited from¶
oldReddit?¶
optionaloldReddit?:boolean
Defined in: extension/data/framework/module.ts:66
When true, this setting only applies on old Reddit.
Inherited from¶
placeholder?¶
optionalplaceholder?:string
Defined in: extension/data/framework/module.ts:85
Placeholder text shown inside empty text inputs
Inherited from¶
preview?¶
optionalpreview?:string
Defined in: extension/data/framework/module.ts:91
Preview text or HTML shown alongside this setting
Inherited from¶
previewImageUrl?¶
optionalpreviewImageUrl?:string
Defined in: extension/data/framework/module.ts:89
URL of a preview image shown alongside this setting
Inherited from¶
sharedPolicy?¶
optionalsharedPolicy?: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¶
step?¶
optionalstep?:number
Defined in: extension/data/framework/module.ts:64
Step size for numeric settings
Inherited from¶
storageKey¶
storageKey:
string
Defined in: extension/data/framework/module.ts:174
Overrides¶
type¶
type:
SettingType
Defined in: extension/data/framework/module.ts:50
Input type for this setting.
Inherited from¶
valueLabels?¶
optionalvalueLabels?: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¶
valueNotes?¶
optionalvalueNotes?: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¶
values?¶
optionalvalues?: readonlystring[]
Defined in: extension/data/framework/module.ts:68
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: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.