Brazen Framework - Utilities

Utilities and helpers for Brazen user scripts framework

Tento skript by nemal byť nainštalovaný priamo. Je to knižnica pre ďalšie skripty, ktorú by mali používať cez meta príkaz // @require https://update.greasyfork.org/scripts/375557/1876577/Brazen%20Framework%20-%20Utilities.js

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Advertisement:

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

Advertisement:

Autor
brazenvoid
Verzia
5.0.0
Vytvorené
15.12.2018
Aktualizované
15.07.2026
Veľkosť
15,5 KB
Licencia
GPL-3.0-only

Brazen Framework — Utilities (developer guide)

Foundation module: small, site-agnostic building blocks used by the Brazen Framework stack. As a script author, you’ll mostly touch these through BrazenFramework helpers and through other modules (Configuration Manager, View Layer), not by treating Utilities as a standalone layer.

Greasy Fork: Utilities · Loads first among framework modules (after jQuery).


When to use / when not to use

  • Use this module when you need one of the framework’s shared primitives: DOM mutation watching, storage wrappers, selector/id generation, statistics labels, validation helpers, or tiny async helpers like sleep.
  • Don’t use this module to build UI or settings schemas — that belongs to the View Layer and Configuration Manager.

Quick start

These are the two most common “surface-level” utilities you’ll see in app code that extends BrazenFramework:

// Watch a list for new nodes (useful outside the main compliance pipeline).
ChildObserver.create()
  .onNodesAdded((nodes) => {
    // nodes: Node[]
  })
  .observe(document.querySelector('#results'))

// Throttle or delay between operations.
await Utilities.sleep(250)

Features

DOM observation: ChildObserver

What it does: A fluent wrapper over MutationObserver for childList add/remove events on a single target node.

Typical use cases:

  • Watching a site widget that’s unrelated to item compliance (e.g. a sidebar that updates via AJAX).
  • Running a one-off enhancement when new rows/cards are appended.

How it works (developer-relevant):

  • Observes one node at a time (observe(node)).
  • Provides separate callbacks for added vs removed nodes.
  • You can pause/resume without rebuilding the observer.

APIs:

  • ChildObserver.create() → factory
  • observe(node) → attach to a Node
  • onNodesAdded(handler) / onNodesRemoved(handler)(nodes, previousSibling, nextSibling, target) => void
  • pauseObservation() / resumeObservation()

Notes: The framework itself uses ChildObserver on each itemListSelectors entry so infinite scroll and AJAX lists get compliance automatically. Use it directly only when you’re doing DOM work outside that pipeline.


Stable ids/selectors: SelectorGenerator

What it does: Generates prefixed element ids/selectors from human-readable names. The rest of the stack uses this to keep UI ids stable and script-scoped.

Typical use cases:

  • When you need to create your own DOM nodes but still want to align with the stack’s id conventions.

APIs:

  • new SelectorGenerator(selectorPrefix) (typically your scriptPrefix)
  • getSelector(selector)prefix + selector
  • getSettingsInputSelector(settingName){prefix}{kebab-name}-setting
  • getSettingsRangeInputSelector(name, getMin){prefix}{kebab-name}-min-setting / -max-setting
  • getStatLabelSelector(statisticType) → element id used by stat labels

Filter removal counts: StatisticsRecorder

What it does: Tracks how many items were removed (failed validation) per filter and updates matching DOM stat labels.

Typical use cases:

  • You usually get this via the framework, but direct use is straightforward when building custom hide/show logic.

Key behavior: record(type, validationResult) increments counters only when validationResult is falsy (i.e. the item failed a filter).

APIs:

  • new StatisticsRecorder(selectorPrefix)
  • record(statisticType, validationResult, value = 1)
  • getTotal(), reset(), updateUI()

Per-rule hide diagnostics: ComplianceRuleRecorder

What it does: When enabled (via framework trackComplianceRules: true), records “which rule caused hides” so the UI can display a breakdown.

APIs:

  • record(configKey, ruleLabel, count = 1)
  • reset()
  • getReport(resolveFilterLabel?)[{ filterKey, filterLabel, rules: [{ label, count }] }]

Small general helpers: Utilities (static)

What it does: A grab-bag of small utilities the framework stack depends on.

Commonly used APIs:

  • sleep(ms) → Promise-based delay
  • toKebabCase(text) → used for tab ids and config keys
  • trimAndKeepNonEmptyStrings(strings[])
  • buildWholeWordMatchingRegex(words[]) → used by blacklist filters
  • callEventHandler, callEventHandlerOrFail, processEventHandlerQueue
  • generateId(prefix?)
  • objectToJSON(object) / objectFromJSON(json)

Example:

await Utilities.sleep(500)
const pattern = Utilities.buildWholeWordMatchingRegex(['foo', 'bar'])

Validation & sanitization helpers: Validator (static)

What it does: Common validation and sanitization helpers used by range filters, tag/text rules, and text normalization.

Commonly used APIs:

  • isInRange(value, lower, upper) → inclusive bounds; supports “only min” or “only max”
  • sanitize(text, rules) → apply regex replacements then trim()
  • regexMatches(text, rules) / validateTextDoesNotContain(text, rules)
  • DOM helpers: doesChildExist, isChildMissing
  • Title/text helpers: sanitizeTextNode, sanitizeNodeOfSelector
  • iFramesRemover() → injects iframe { display: none !important; } (requires style injection grant)

Public API reference (index)

  • Constants: REGEX_LINE_BREAK, REGEX_PRESERVE_NUMBERS
  • Classes: ChildObserver, SelectorGenerator, StatisticsRecorder, ComplianceRuleRecorder
  • Statics: Utilities.*, Validator.*

Removed in v5.0.0: LocalStore, storage drivers — persistence is IndexedDB via Configuration Manager; legacy import helpers are in IndexedDB Storage.


Integration notes (grants, load order, pitfalls)

  • Grants: this module declares no Tampermonkey grants. Put GM_addStyle, GM_download, GM_getValue, GM_setValue, etc. on the application script as needed.
  • Load order: load after jQuery, before all other Brazen modules.
  • Next in stack: View Layer