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
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).
sleep.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)
ChildObserverWhat it does: A fluent wrapper over MutationObserver for childList add/remove events on a single target node.
Typical use cases:
How it works (developer-relevant):
observe(node)).APIs:
ChildObserver.create() → factoryobserve(node) → attach to a NodeonNodesAdded(handler) / onNodesRemoved(handler) → (nodes, previousSibling, nextSibling, target) => voidpauseObservation() / 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.
SelectorGeneratorWhat 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:
APIs:
new SelectorGenerator(selectorPrefix) (typically your scriptPrefix)getSelector(selector) → prefix + selectorgetSettingsInputSelector(settingName) → {prefix}{kebab-name}-settinggetSettingsRangeInputSelector(name, getMin) → {prefix}{kebab-name}-min-setting / -max-settinggetStatLabelSelector(statisticType) → element id used by stat labelsStatisticsRecorderWhat it does: Tracks how many items were removed (failed validation) per filter and updates matching DOM stat labels.
Typical use cases:
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()ComplianceRuleRecorderWhat 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 }] }]Utilities (static)What it does: A grab-bag of small utilities the framework stack depends on.
Commonly used APIs:
sleep(ms) → Promise-based delaytoKebabCase(text) → used for tab ids and config keystrimAndKeepNonEmptyStrings(strings[])buildWholeWordMatchingRegex(words[]) → used by blacklist filterscallEventHandler, callEventHandlerOrFail, processEventHandlerQueuegenerateId(prefix?)objectToJSON(object) / objectFromJSON(json)Example:
await Utilities.sleep(500)
const pattern = Utilities.buildWholeWordMatchingRegex(['foo', 'bar'])
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)doesChildExist, isChildMissingsanitizeTextNode, sanitizeNodeOfSelectoriFramesRemover() → injects iframe { display: none !important; } (requires style injection grant)REGEX_LINE_BREAK, REGEX_PRESERVE_NUMBERSChildObserver, SelectorGenerator, StatisticsRecorder, ComplianceRuleRecorderUtilities.*, Validator.*Removed in v5.0.0: LocalStore, storage drivers — persistence is IndexedDB via Configuration Manager; legacy import helpers are in IndexedDB Storage.
GM_addStyle, GM_download, GM_getValue, GM_setValue, etc. on the application script as needed.