Class: CSSTweaks<TPath>
utilities/css-tweaks.CSSTweaks
A Module represents a distinct logical component of FrankerFaceZ. Modules can be loaded or unloaded at runtime, and they have a robust event system. Every add-on consists of one or more Module. There are separate modules for every system in FrankerFaceZ, such as localization, emotes, badges, chat rendering, etc.
If you are creating an add-on, you might use Module directly if you're using more than one module. If your add-on only has one module, then it should use the Addon subclass.
Type parameters
Name | Type | Description |
---|---|---|
TPath | extends string = "site.css_tweaks" | The absolute path where this module will be mounted in the module tree. Providing this string allows relative events to be used. |
Hierarchy
Module
<TPath
>↳
CSSTweaks
Constructors
constructor
• new CSSTweaks<TPath
>(name?
, parent?
, loader?
): CSSTweaks
<TPath
>
Type parameters
Name | Type |
---|---|
TPath | extends string = "site.css_tweaks" |
Parameters
Name | Type |
---|---|
name? | string |
parent? | GenericModule |
loader? | RequireContext |
Returns
CSSTweaks
<TPath
>
Overrides
Defined in
src/utilities/css-tweaks.ts:25
Properties
chunks
• chunks: Record
<string
, string
> = {}
Stores CSS chunks loaded by the provided loader, and used with the toggle method.
Defined in
src/utilities/css-tweaks.ts:18
rules
• rules: Record
<string
, string
> = {}
Stores CSS rules used with the toggleHide method.
Defined in
src/utilities/css-tweaks.ts:15
should_enable
• Optional
should_enable: boolean
For use in modules that are direct children of "core" or "site". If this is set to true, the module will be enabled when FrankerFaceZ is initialized.
Inherited from
Defined in
Accessors
addon_id
• get
addon_id(): undefined
| string
If this module is part of an add-on, the add-on's ID.
Returns
undefined
| string
Inherited from
Module.addon_id
Defined in
addon_root
• get
addon_root(): undefined
| GenericModule
If this module is part of an add-on, the add-on's root module.
Returns
undefined
| GenericModule
Inherited from
Module.addon_root
Defined in
chunks_loaded
• get
chunks_loaded(): boolean
Whether or not chunks have been loaded using the ().
Returns
boolean
Defined in
src/utilities/css-tweaks.ts:35
enabled
• get
enabled(): boolean
Whether or not the module is State.Enabled.
Returns
boolean
Inherited from
Module.enabled
Defined in
enabling
• get
enabling(): boolean
Whether or not the module is State.Enabling.
Returns
boolean
Inherited from
Module.enabling
Defined in
load_state
• get
load_state(): LoadState
The current LoadState of this module.
Returns
Inherited from
Module.load_state
Defined in
loaded
• get
loaded(): boolean
Whether or not the module is LoadState.Loaded.
Returns
boolean
Inherited from
Module.loaded
Defined in
loader
• get
loader(): undefined
| null
| RequireContext
An optional require context that can be used for loading arbitrary, named CSS chunks.
Returns
undefined
| null
| RequireContext
Defined in
src/utilities/css-tweaks.ts:40
• set
loader(value
): void
Parameters
Name | Type |
---|---|
value | undefined | null | RequireContext |
Returns
void
Defined in
src/utilities/css-tweaks.ts:44
loading
• get
loading(): boolean
Whether or not the module is LoadState.Loading.
Returns
boolean
Inherited from
Module.loading
Defined in
log
• get
log(): Logger
A Logger instance for this module.
Returns
Inherited from
Module.log
Defined in
• set
log(log
): void
Parameters
Name | Type |
---|---|
log | Logger |
Returns
void
Inherited from
Module.log
Defined in
path
• get
path(): TPath
Returns
TPath
Inherited from
Module.path
Defined in
state
• get
state(): State
The current State of this module.
Returns
Inherited from
Module.state
Defined in
style
• get
style(): ManagedStyle
The ManagedStyle instance used internally by this CSSTweaks instance.
Returns
Defined in
src/utilities/css-tweaks.ts:53
Methods
_time
▸ _time(event
): void
Record a timing event. The timing system is not yet finished.
Parameters
Name | Type | Description |
---|---|---|
event | any | The timing event to record. |
Returns
void
Inherited from
Defined in
abs_path
▸ abs_path(path
): string
Parameters
Name | Type |
---|---|
path | string |
Returns
string
Inherited from
Defined in
canDisable
▸ canDisable(): boolean
Determine whether or not this module can be disabled. This checks not only this module's state, but the state of all modules that depend on this module.
Returns
boolean
Inherited from
Defined in
canUnload
▸ canUnload(): boolean
Determine whether or not this module can be unloaded. This checks not only this module's state, but the state of all modules that depend on this module.
Returns
boolean
Inherited from
Defined in
delete
▸ delete(key
): void
Delete a CSS block from this CSSTweak instance's ManagedStyle instance. This can be used to delete managed blocks including those set by (), (), and setVariable to please use caution.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key to be deleted. |
Returns
void
See
Defined in
src/utilities/css-tweaks.ts:157
deleteVariable
▸ deleteVariable(key
): void
Delete a CSS variable.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key for the variable |
Returns
void
Defined in
src/utilities/css-tweaks.ts:178
disable
▸ disable(): undefined
| null
| Promise
<void
>
Disable this module. If the module has no onDisable method, but it has an onEnable method, then this will throw an error.
As part of disabling this module, all modules that depend on this module will be disabled first. All modules that depend on this module as a load dependency will be unloaded first.
Please note that, if any of those dependencies cannot be unloaded or disabled, this will fail.
Returns
undefined
| null
| Promise
<void
>
Inherited from
Defined in
emit
▸ emit<K
>(event
, ...args
): void
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type |
---|---|
event | K |
...args | ModuleEvents [K ] |
Returns
void
Inherited from
Defined in
enable
▸ enable(): undefined
| null
| Promise
<void
>
Enable this module. If the module has no onEnable method and the module is considered LoadState.Loaded immediately, then the module will be considered State.Enabled immediately.
All of the module's requires dependencies will be enabled before the state updates and this returns.
Modules are automatically loaded before being enabled.
Returns
undefined
| null
| Promise
<void
>
Inherited from
Defined in
events
▸ events(): string
[]
Returns
string
[]
Inherited from
Defined in
eventsWithChildren
▸ eventsWithChildren(): string
[]
Returns
string
[]
Inherited from
Defined in
getAddonProxy
▸ getAddonProxy(addon_id
, addon
, root
, caller
): Module
<""
, ModuleEvents
>
Optional. This method is called when a module belonging to an Addon attempts to () or () this module. This can be used to return a Proxy for the purpose of adjusting API responses or record keeping.
Parameters
Name | Type | Description |
---|---|---|
addon_id | string | The ID of the add-on requesting the module. |
addon | AddonInfo | The manifest of the add-on requesting the module. |
root | GenericModule | The root Addon module. |
caller | GenericModule | The specific Module making the request. |
Returns
Module
<""
, ModuleEvents
>
Inherited from
Defined in
hasListeners
▸ hasListeners<K
>(event
): boolean
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type |
---|---|
event | K |
Returns
boolean
Inherited from
Defined in
hasModule
▸ hasModule(name
): boolean
Parameters
Name | Type |
---|---|
name | string |
Returns
boolean
Inherited from
Defined in
inject
▸ inject(name
, module?
, require?
): null
| GenericModule
Parameters
Name | Type | Default value |
---|---|---|
name | null | string | Module <"" , ModuleEvents > | undefined |
module? | null | typeof Module | GenericModule | undefined |
require | boolean | true |
Returns
null
| GenericModule
Inherited from
Defined in
injectAs
▸ injectAs(variable
, name
, module?
, require?
): null
| GenericModule
Parameters
Name | Type | Default value |
---|---|---|
variable | string | undefined |
name | null | string | Module <"" , ModuleEvents > | undefined |
module? | null | typeof Module | GenericModule | undefined |
require | boolean | true |
Returns
null
| GenericModule
Inherited from
Defined in
listeners
▸ listeners<K
>(event
): ListenerInfo
<any
[]>[]
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type |
---|---|
event | K |
Returns
ListenerInfo
<any
[]>[]
Inherited from
Defined in
load
▸ load(): undefined
| null
| Promise
<void
>
Load this module. If the module has no onLoad method and no load_requires modules listed, then it will be considered LoadState.Loaded immediately.
All of the module's load_requires dependencies will be enabled before the load state updates and this returns.
Modules are automatically loaded before being enabled.
Returns
undefined
| null
| Promise
<void
>
Inherited from
Defined in
loadFromContext
▸ loadFromContext(ctx
, log?
): Promise
<Record
<string
, Module
<""
, ModuleEvents
>>>
Attempt to load a set of child modules from a require.context object. This searches the default exports, as well as exports named module
specifically. Each discovered module will be registered and injected onto this module.
Parameters
Name | Type | Description |
---|---|---|
ctx | RequireContext | The context to load from. |
log? | Logger | A logger to use for logging errors. If not provided, this will default to this module's default logger. |
Returns
Promise
<Record
<string
, Module
<""
, ModuleEvents
>>>
A map of all loaded modules.
Inherited from
Defined in
makeEvent
▸ makeEvent<TData
>(data
): TypedFFZEvent
<TData
>
Create a new FFZEvent instance. This is a convenience method that wraps ()
Type parameters
Name | Type |
---|---|
TData | extends Record <string , any > = {} |
Parameters
Name | Type |
---|---|
data | TData |
Returns
TypedFFZEvent
<TData
>
Inherited from
Defined in
makeWaitableEvent
▸ makeWaitableEvent<TData
, TReturn
>(data
): TypedFFZWaitableEvent
<TData
, TReturn
>
Create a new FFZWaitableEvent instance. This is a convenience method that wraps ()
Type parameters
Name | Type |
---|---|
TData | extends Record <string , any > = {} |
TReturn | void |
Parameters
Name | Type |
---|---|
data | TData |
Returns
TypedFFZWaitableEvent
<TData
, TReturn
>
Inherited from
Defined in
many
▸ many<K
>(event
, ttl
, fn
, ctx?
, priority?
, prepend?
): void
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type | Default value |
---|---|---|
event | K | undefined |
ttl | number | undefined |
fn | EventListener <ModuleEvents [K ]> | undefined |
ctx? | any | undefined |
priority? | number | undefined |
prepend | boolean | false |
Returns
void
Inherited from
Defined in
off
▸ off<K
>(event?
, fn?
, ctx?
): void
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type |
---|---|
event? | K |
fn? | EventListener |
ctx? | any |
Returns
void
Inherited from
Defined in
offContext
▸ offContext<K
>(event
, ctx?
): void
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type |
---|---|
event | K |
ctx? | any |
Returns
void
Inherited from
Defined in
on
▸ on<K
>(event
, fn
, ctx?
, priority?
, prepend?
): void
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type | Default value |
---|---|---|
event | K | undefined |
fn | EventListener <ModuleEvents [K ]> | undefined |
ctx? | any | undefined |
priority? | number | undefined |
prepend | boolean | false |
Returns
void
Inherited from
Defined in
onDisable
▸ onDisable(): void
| Promise
<void
>
Optional. If this method is defined, it will be called when the module is being disabled. The module will not be set to State.Disabled until after this method returns. Promises are supported.
Returns
void
| Promise
<void
>
Inherited from
Defined in
onEnable
▸ onEnable(): void
| Promise
<void
>
Optional. If this method is defined, it will be called when the module is being enabled. The module will not be set to State.Enabled until after this method returns. Promises are supported.
When this is called, all modules that this module requires will already be enabled and injected modules will have been injected.
Returns
void
| Promise
<void
>
Inherited from
Defined in
onLoad
▸ onLoad(): void
| Promise
<void
>
Optional. If this method is defined, it will be called when the module is being loaded. The module will not be set to LoadState.Loaded until after this method returns. Promises are supported.
When this is called, all modules that this module load_requires will already be enabled and injected modules will have been injected.
Returns
void
| Promise
<void
>
Inherited from
Defined in
onUnload
▸ onUnload(): void
| Promise
<void
>
Optional. If this method is defined, it will be called when the module is being unloaded. The module will not be set to LoadState.Unloaded until after this method returns. Promises are supported.
When this is called, all modules that depend on this module will already have been disabled.
Returns
void
| Promise
<void
>
Inherited from
Defined in
once
▸ once<K
>(event
, fn
, ctx?
, priority?
, prepend?
): void
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type | Default value |
---|---|---|
event | K | undefined |
fn | EventListener <ModuleEvents [K ]> | undefined |
ctx? | any | undefined |
priority? | number | undefined |
prepend | boolean | false |
Returns
void
Inherited from
Defined in
register
▸ register(name
, module
, inject_reference?
): Module
<any
, ModuleEvents
>
Parameters
Name | Type | Default value |
---|---|---|
name | string | undefined |
module | typeof Module | undefined |
inject_reference | boolean | false |
Returns
Module
<any
, ModuleEvents
>
Inherited from
Defined in
resolve
▸ resolve(name
): null
| Module
<""
, ModuleEvents
>
Parameters
Name | Type |
---|---|
name | string | Module <"" , ModuleEvents > |
Returns
null
| Module
<""
, ModuleEvents
>
Inherited from
Defined in
set
▸ set(key
, value
): void
Include an arbitrary string of CSS using this CSSTweak instance's ManagedStyle instance. This will override any existing CSS block using the same key.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key for the CSS block. |
value | string | The text content of the CSS block. |
Returns
void
See
Defined in
src/utilities/css-tweaks.ts:146
setVariable
▸ setVariable(key
, value
, scope?
): void
Set a CSS variable. The variable's name will be prefixed with ffz-
so, for example, if key is "link-color"
then the resulting CSS variable will be --ffz-link-color
and can be used with var(--ffz-link-color)
.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
key | string | undefined | The key for the variable. |
value | string | undefined | The value of the variable. |
scope | string | 'body' | The scope this variable should be set on. Defaults to "body" . |
Returns
void
Defined in
src/utilities/css-tweaks.ts:170
toggle
▸ toggle(key
, force?
): void
If force is not set, this toggles a specific CSS chunk, enabling it if it was not previously enabled and vice versa. If force is provide, it will either enable or disable the specific CSS chunk based on the boolean value of force.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key for the CSS block in chunks. |
force? | boolean | Optional. The desired state. |
Returns
void
Defined in
src/utilities/css-tweaks.ts:99
toggleHide
▸ toggleHide(key
, force?
): void
If force is not set, this toggles a specific element hiding rule, enabling it if it was not previously enabled and vice versa. If force is provided, it will either enable or disable the specific element hiding rule based on the boolean value of force.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key for the element hiding rule in rules. |
force? | boolean | Optional. The desired state. |
Returns
void
Throws
If the provided key is not within rules.
Defined in
src/utilities/css-tweaks.ts:70
unload
▸ unload(): undefined
| null
| Promise
<void
>
Unload this module. If the module has no onUnload method, but it has an onLoad method, then this will throw an error.
When this is called, if this module is currently enabled, it will be disabled first. As part of that, all modules that depend on this module will also be disabled first. All modules that depend on this module as a load dependency will be unloaded first.
Please note that, if any of those dependencies cannot be unloaded or disabled, this will fail.
Returns
undefined
| null
| Promise
<void
>
Inherited from
Defined in
waitFor
▸ waitFor<K
>(event
, ctx?
, priority?
, prepend?
): Promise
<ModuleEvents
[K
]>
Type parameters
Name | Type |
---|---|
K | extends string |
Parameters
Name | Type | Default value |
---|---|---|
event | K | undefined |
ctx? | any | undefined |
priority? | number | undefined |
prepend | boolean | false |
Returns
Promise
<ModuleEvents
[K
]>